AAlgoLab
ALG-H016HardDynamic Programming

Longest Mirror Subsequence

Return the length of the longest subsequence of text that reads the same forward and backward. Characters may be skipped without changing order.

Contract

input text: string
return integer

Constraints

  • • 0 <= text length <= 1000

Examples

Example 1
text = "bbbab"
→ 4
Example 2
text = "cbbd"
→ 2

5 judge tests (2 shown above). Target complexity: O(n^2).