Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 516 Longest Palindromic Subsequence - Problem Statement

LeetCode 516

Solve Longest Palindromic Subsequence from LeetCode. Given a string, find the longest subsequence that reads the same forwards and backwards.

Hint: This reduces to LCS. Compare the string with its reverse. The LCS of a string and its reverse is the longest palindromic subsequence. For 'bbbab', the answer is 44: the subsequence 'bbbb' uses indices 00, 11, 22, 44 and reads the same forwards and backwards.