Best algo for finding no. of steps required to convert a sequence to a palindromic sequence

117 Views Asked by At

[My first question of Math SE, so, HI!] I'm not sure of what the rules are around the place, but I have a straightforward question as follows...

The sequences 23, 45, 23 and 23, 45, 56, 23, 23, 56, 45, 23 are examples of palindromes. The sequence 23, 45, 56 is not a palindrome. The sequence 23, 32 is not a palindrome either. A sequence of length 1 is always a palindrome. A given sequence of integers can be broken up into parts such that each of them is a palindrome. Consider the sequence 34,45,34,56,34. This can be broken up into 3 palindrome sequences with 34, 45, 34 constituting the first, 56 constituting the second and 34 constituting the third. It can also be broken in 5 palindrome sequences each containing a single number.

We want to determine the smallest number K such that the given sequence can be broken up into K palindrome sequences.

1

There are 1 best solutions below

5
On

Hint: think about numbers that appear only once in the sequence. Then think again.