Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

177. Longest Palindromic Subsequence

MediumDay 52 of 60Dynamic Programming

Given a string s, return the length of its longest palindromic subsequence. A subsequence keeps the original order of characters but may skip some of them; it does not have to be contiguous.

Example 1
Input: s = "bbbab"
Output: 4
"bbbb" is a palindromic subsequence of length 4.
Example 2
Input: s = "cbbd"
Output: 2
"bb" is the longest one.
Constraints
  • 1 <= s.length <= 1000
  • `s` has only lowercase English letters
Hints
Frequently asked at: Amazon, LinkedIn, Google
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min