Problems > Longest Palindromic Subsequence

Longest Palindromic Subsequence

Difficulty: 1700 3000 ms 128 MB

strings dp

Print the length of the longest subsequence of S that is a palindrome.

Input: one line with the string S.

Output: the longest palindromic subsequence length.

Constraints:

  • 1 ≤ |S| ≤ 1000
  • lowercase letters

Sample Tests

Input 1
bbbab
Output 1
4
Input 2
abcd
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.