Given a string "ababacba"
, how can I generate all possible palindrome substrings?
I was thinking of an approach of the following:
- Generate a suffix trie with the original string
- Reverse the string
- Generate all suffixes of the reversed string
- For each of this suffixes, compare by going each node in the suffix trie to determine palindrome
However, it seems that this might not work for certain cases such as it detects baba
as a palindrome when it is not, because reading ababacba is the same as reading ababacba, both bolded statement have abab
and its reversed baba
.
Hence, I think this approach is not valid, so how can I generate all palindrome substrings using a trie?
Desired output for string ababacba
:
ababa
bab
aba
Thank you.