Count double palindromes in given int sequence

Posted by jakubmal on Stack Overflow See other posts from Stack Overflow or by jakubmal
Published on 2010-06-09T20:11:17Z Indexed on 2010/06/09 20:32 UTC
Read the original article Hit count: 167

For a given int sequence check number of double palindromes, where by double palindrome we mean sequence of two same palindromes without break between them. So for example:

in 1 0 1 1 0 1 we have 1 0 1 as a palindrome which appears 2 times without a break,

in 1 0 1 5 1 0 1 we have 1 0 1 but it's separated

(apart from the other palindromes in these sequences)

Problem example test data is:

3

12 0 1 1 0 0 1 1 0 0 1 1 0

12 1 0 1 0 1 0 1 0 1 0 1 0

6 3 3 3 3 3 3

with answers

8 0 9

Manacher is obvious for the begging, but I'm not sure what to do next. Any ideas appreciated. Complexity should be below n^2 I guess.

EDIT: int is here treated as single element of alphabet

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about palindrome