Longest Palindromic Subsequence Problem Statement

Given a string A consisting of lowercase English letters, determine the length of the longest palindromic subsequence within A.

Explanation:

  • A subsequence is derived from a string by deleting some or no characters without changing the order of the remaining characters.
  • A string is a palindrome if it reads the same forwards and backwards (e.g., "abba").

Input:

The first line contains an integer ‘T’, indicating the number of test cases. Each test case consists of a single string ‘A’.

Output:

Output a single integer per test case, representing the length of the longest palindromic subsequence in ‘A’.

Example:

Input: 
2
bbabcbcab
dcbccbcabbb

Output:
7
7

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 102
  • Where ‘T’ represents the number of test cases and ‘N’ represents the length of the string.
  • Time limit: 1 second.

Note:

No need to print anything; implement the function to obtain the result.
AnswerBot
4mo

The task is to find the length of the longest palindromic subsequence in a given string.

  • Iterate through the string and create a 2D array to store the lengths of palindromic subsequences.

  • Use dynamic pr...read more

Help your peers!
Select
Add answer anonymously...

MasterCard Full Stack Engineer interview questions & answers

A Full Stack Engineer was asked Q. Next Greater Node in Linked List Problem Statement In a set of linked ninja vill...read more
A Full Stack Engineer was asked Q. Word Pattern Problem Statement Given two strings S and T, determine if S follows...read more
A Full Stack Engineer was asked Q. Longest Palindromic Subsequence Problem Statement Given a string A consisting of...read more

Popular interview questions of Full Stack Engineer

A Full Stack Engineer was asked Q1. Next Greater Node in Linked List Problem Statement In a set of linked ninja vill...read more
A Full Stack Engineer was asked Q2. Word Pattern Problem Statement Given two strings S and T, determine if S follows...read more
A Full Stack Engineer was asked Q3. Longest Palindromic Subsequence Problem Statement Given a string A consisting of...read more
MasterCard Full Stack Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits