Assume we have a list of integers, for example:
L = [13,13,4,13,4,2]
I want to find the set of all palindromes, where each palindrome is a sub-list of L
containing contiguous integers. For the above list that would be:
S = {[13], [4], [2], [13,13], [13,4,13], [4,13,4]}
Because the inverse of L
would be L' = [2,4,13,4,13,13]
, and every element of S
appears in L'
in the correct order.
How can I find the set of all palindromes in general? My naive approach would be to check if each element of the power set of L
appears in L'
, but this is inefficient and I am sure that there is a better solution.