Close
Topic list
Longest Palindromic Subsequence
HARD
45 mins
Dynamic Programming
Topics (Covered in this problem)
Problem solved
Skill meter
Dynamic Programming
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Longest Palindromic Subsequence

Contributed by
Deepanshu_1780
Hard
0/120
Avg time to solve 45 mins
Success Rate 50 %
Share

Problem Statement

A string is said to be palindrome if the reverse of the string is the same as the actual string. For example, “abba” is a palindrome, but “abbc” is not a palindrome.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
``````2
bbabcbcab
bbbab
``````
Sample Output 1:
``````7
4
``````
Explanation of Sample Input 1:
``````For the first test case, the longest palindromic subsequence is “babcbab”, which has a length of 7. “bbbbb” and “bbcbb” are also palindromic subsequences of the given string, but not the longest one.

For the second test case, the longest palindromic subsequence is “bbbb”, which has a length of 4.
``````
Sample Input 2:
``````3
cbbd
bebeeed
abcd
``````
Sample Output 2:
``````2
4
1
``````
Auto
Console