DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
String

Longest Palindromic Subsequence

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Longest Palindromic Subsequence** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** 2D DP or reverse + LCS **Edge Cases to Consider:** - (1) All same characters - (2) Single character - (3) No repeated chars

Examples

Example 1
Input: "bbbab"
Output: 4
Explanation: "bbbb" (delete a) wait: "bbab" → "bbb" not possible. "bbbb"? Only 3 b's. "bbab"→ LPS is "bbb"? No: positions 0,1,3 are "bbb" length 3, or 0,1,2,4 = "bbbb"? char at 4 is 'b'. Yes: "bbbb" length 4
Example 2
Input: "cbbd"
Output: 2
Explanation: "bb"
Example 3
Input: "a"
Output: 1

Constraints

  • ▪1 <= s.length <= 10^4
  • ▪s consists of printable ASCII characters
  • ▪Solve with optimal space complexity

Watch Out For Edge Cases

  • ▪All same characters
  • ▪Single character
  • ▪No repeated chars
Frequently Asked At
AmazonGoogleMicrosoftAdobe