Grokking Dynamic Programming Patterns for Coding Interviews

0% completed

Longest Palindromic Subsequence

Problem Statement

Try it yourself

Problem Statement

Given a sequence, find the length of its Longest Palindromic Subsequence (LPS). In a palindromic subsequence, elements read the same backward and forward.

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: "abdbca"
Output: 5
Explanation: LPS is "abdba".

Example 2:

Input: = "cddpd"
Output: 3
Explanation: LPS is "ddd".

Example 3:

Input: = "pqr"
Output: 1
Explanation: LPS could be "p", "q" or "r".

Constraints:

  • 1 <= st.length <= 1000
  • sy consists only of lowercase English letters.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .
Mark as Completed
M

Mircea C

· 4 years ago

For the memoisation tecgnique, isn’t the time complexity still 2^n? We still have 2^n function calls...

Show 1 reply

On This Page

Problem Statement

Try it yourself