Participate in Codex, Test Your Skills & Win BIG

Longest Palindromic Subsequence

Problem Description

Given a string A, find the common palindromic sequence ( A sequence which does not need to be contiguous and is a pallindrome), which is common in itself.

You need to return the length of longest palindromic subsequence in A.


  • Your code will be run on multiple test cases (<=10). Try to come up with an optimised solution.

  • Problem Constraints

    1 <= |A| <= 1005

    Input Format

    First and only argument is an string A.

    Output Format

    Return a integer denoting the length of longest palindromic subsequence in A.

    Example Input

    Input 1:

     A = "bebeeed"

    Example Output

    Output 1:


    Example Explanation

    Explanation 1:

     The longest common pallindromic subsequence is "eeee", which has a length of 4

    NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
    Start solving Longest Palindromic Subsequence on Interview Code Editor
    • Hint 1
    • Solution Approach
    • Complete Solution
    Asked In:


    Click here to start solving coding interview questions