A totem pole is carved with a single row of glyphs, encoded as a string of lowercase English letters. A symmetric run is any subsequence (glyphs chosen left to right, not necessarily adjacent, keeping their order) that reads identically forward and backward.
Find the length of the longest symmetric run that can be selected from the carving.
A single line containing the glyph string s (lowercase English letters only).
A single integer: the length of the longest palindromic subsequence of s.
s <= 2000s contains only lowercase English letters (a-z).Example 1
Input
bxbxb
Expected
5
Explanation
The whole string reads the same backward, so the longest symmetric run is 'bxbxb' itself, of length 5.
Example 2
Input
abcda
Expected
3
Explanation
No length-4 symmetric run exists, but 'aba' (positions 1, 2, 5) or 'ada' (positions 1, 4, 5) give length 3.
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 →