A decorative mosaic frieze is encoded as a string of lowercase letters. A restoration wants to keep the largest symmetric pattern possible by removing some tiles: find the length of the longest subsequence of the string that is a palindrome (reads the same left to right and right to left).
Line 1: the frieze string s.
A single integer: the length of the longest palindromic subsequence of s.
s <= 40s consists of lowercase English letters only.Example 1
Input
bbbab
Expected
4
Explanation
The subsequence bbbb (length 4) is a palindrome and is the longest such subsequence.
Example 2
Input
cbbd
Expected
2
Explanation
The subsequence bb (length 2) is the longest palindromic subsequence.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →