FunctionRacerProblemsRace

Longest Mirror Subsequence

MediumDynamic programmingPython, JavaScript, TypeScript, Java, C++

Delete any characters you like from text (possibly none) without reordering the rest, so that what remains reads the same forwards and backwards. Return the largest possible length of what remains. A single character always qualifies, and the empty string gives 0.

Example 1

text "bbabcb"
returns 5

Deleting the c leaves bbabb, which reads the same both ways; nothing longer works.

Example 2

text "abcd"
returns 1

All four characters differ, so only a single character can remain.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems