DIRECTI On-Campus Hiring OA (2021) | Longest Palindromic Subsequence Using Dynamic Programming

Directi · Question · Posted Jun 2026

Problem Statement Given a string s, find the length of the Longest Palindromic Subsequence (LPS). A subsequence can be formed by deleting zero or more characters without changing the relative order of the remaining characters. A palindrome reads the same forwards and backwards. Return the length of the longest palindromic subsequence present in the string. Example 1 Input: s = "bbbab" Output: 4 Explanation One longest palindromic subsequence is: "bbbb" Length = 4 Example 2 Input: s = "cbbd" Output: ...

The full answer & interview discussion are available to premium members.

Log in Create a free account