What's the meaning of this problem?

  • 3

    Submission Result: Wrong Answer

    Input: "efe"
    Output: [["e","f","e"]]
    Expected: [["e","f","e"],["efe"]]

    It said:
    "Given a string s, partition s such that every substring of the partition is a palindrome."

    Is every substring of "efe" a palindrome? for example: the "ef" ?
    I'm very confuse about it.

  • 2

    The items listed in the answer are the substrings of the partition. To partition something means to divide it, the substrings of the partition are the parts of the original string that remain in one piece once the division occurs. You do not need to have the substrings of the substrings be palindromes, since following that logic, you end up with only single letters, or strings made up exclusively of a single letter repeated n times.

    Since the whole string, when divided 0 times, is a palindrome, it is a substring of a partition that is a palindrome, and thus is in the answer.

  • 1

    Let me give an example to understand the problem statement:

    Input: "ababcb"

    So we start finding the palindromes with "1" character:

    [a, b, a, b, c, b]

    The next we do is consider palindromes of "2" characters:

    • Here we do not have any palindromes which can be formed by "2" characters

    Palindromes of "3" characters:

    [a, bab, c, b],
    [a, b, a, bcb],
    [aba, bcb]

    There are no further palindromes until the length = input.length(), hence the final result will be:

    	[a, b, a, b, c, b],
    	[aba, b, c, b],
    	[a, bab, c, b],
    	[a, b, a, bcb],
    	[aba, bcb]

    Let me know if I am wrong!

Log in to reply

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