Example 1
Input
bbbab
Output
4
One longest palindromic subsequence is 'bbbb', which has length 4.
Full lesson preview
Compute the length of the longest subsequence of a string that reads the same forwards and backwards using dynamic programming.
Problem statement
Task
Examples
Input
bbbab
Output
4
One longest palindromic subsequence is 'bbbb', which has length 4.
Input format
Output format
Constraints
Samples
Input
agbdba
Output
5
A longest palindromic subsequence is 'abdba' of length 5.