Quant Memo
Coding/●●●●

Longest palindromic subsequence

Given a string, find the length of its longest palindromic subsequence: a sequence you get by deleting zero or more characters (keeping order) that reads the same both ways. Unlike a substring, it need not be contiguous.

"bbbab"  -> 4     # "bbbb"
"cbbd"   -> 2     # "bb"
"abc"    -> 1

Return the length in O(n2)O(n^2) time. The expand-around-center trick does not apply here; think in terms of the ends of a range.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions