Standard Bar Dynamic Programming · DP on Strings O(n^2) · O(n^2)
A textile archivist analyzes thread sequences from ancient ribbons, looking for the longest thread pattern that reads identically forwards and backwards after ignoring unrelated threads. The longer the preserved palindrome motif, the more valuable the ribbon's provenance. The catalog needs that motif length per specimen.
Input: A string s.
Output: Return the length of the longest subsequence of s that is a palindrome.
1 <= len(s) <= 1000s consists of lowercase English lettersInput: {"s":"bbbab"}
Output: 4
Dropping the lone 'a' leaves "bbbb" — a length-4 palindrome.
Input: {"s":"cbbd"}
Output: 2
"bb" is the best symmetric motif.