1166. Longest Palindromic Subsequence

EasyDynamic ProgrammingSequence DP

Given a string s, return the length of its longest palindromic subsequence — the longest subsequence that reads the same forward and backward. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the length of the longest palindromic subsequence.

Examples

Example 1
Input: {"s":"bbbab"}
Output: 4
Explanation: 'bbbb' is palindromic.
Example 2
Input: {"s":"cbbd"}
Output: 2
Explanation: 'bb'.
Example 3
Input: {"s":"a"}
Output: 1
Explanation: Single character.

Constraints

Asked by

InfosysAmazonMicrosoftGoogleBloombergMeta
Solve this problem in the editor →