 All Problems
Longest Palindromic Subsequence
medium
string
dynamic programming
amazon
google
microsoft

Given a string s, find the longest palindromic subsequence's length in s.

A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

Example 1:

Input:  bbbab
Output: 4

("bbbb")

Example 2:

Input:  cbbd
Output: 2

("bb")

Constraints:

  • 1 ≤ s.length ≤ 1000
  • s consists only of lowercase English letters

Input format: A single string.

Output format: Length of longest palindromic subsequence.

Run to check your code against the sample cases, or submit to run every case