InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

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.

NOTE:

  • 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:

     4
    


    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
    Sign Up
    to access hints and editorial solutions for Longest Palindromic Subsequence
    Asked In:

    Discussion


    Loading...
    Click here to start solving coding interview questions