What is the meaning of example 1?

  • 8


    I am kind of confused of the first example, which says "bbbab"'s longest palindromic subsequence is "bbbb". Is this a typo or I didn't get the point?

    Thanks in advance!

  • 8

    Check the link here.
    I think the problem should state that find a substring which "contains" the longest palindromic sequence.
    For example:
    Given "abxyzbahj",
    "abxba", "abyba" and "abzba" are the longest palindromic sequence which is in the substring "abxyzba".
    Therefore, the returning answer should be the length of "abxba" which is 5.

  • 2

    The question has a minor clue in it. It says
    Longest Palindromic **Subsequence** and not sub - string.

    Every sub string is a sub sequence, vice versa is not true.

    Sample : leetcode
    Both substring and subsequence leet, code
    Sub sequence ltcode, eecode, ecode, ltde // and not substring
    Neither sequence nor substring tlc, dlt

    I learnt it the hard way!

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.