Search code examples
algorithmpalindrome

iterations of characters are required to make wekqqhibrmxz a palindrome string


Make it a palindrome

How many iterations of characters are required to make wekqqhibrmxz a palindrome string? Consider alphabets to be a circular list, A comes next to Z

1- 131

2- 114

3- 25

4- 15

Can anybody guide the way to go to solve this?


Solution

  • Since you want to make it a palindrome, you would need to make the nth character the same as the (length-n)th character.

    For example, you would need to shift w (the first character) and z (the last character) so that they are the same character.

    Any method of doing that requires a minimum of three "iterations" (eg. w->x->y->z so that the string is zekqqhibrmxz).

    Do this for the first six characters, then take the sum of the iterations for each of the six changes.