-1

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?

  • 1
    It is not clear what do you mean by `iterations` - eg. adding/deleting/shuffling? and what's the rules? If it's from a web site, you can include the source to help clarify. – Daniel Hao Jan 16 '21 at 13:22
  • Considering the letters to be circular suggests that one "iteration" means to shift a letter up or down one place, wrapping around from Z to A. That would make the answer 25, the sum of the distance between first and last letter, second and second to last letter and so on. – M Oehm Jan 16 '21 at 15:21
  • @MOehm yes got it!! Thanks a lot! – The Girl who Codes Jan 17 '21 at 08:30
  • Because this is an interview question, you shouldn't be asking others to help you. It seems that some of the important details were vague, in which case it would be normal to ask the interviewer for clarification. – Elliott Jan 18 '21 at 06:29

1 Answers1

1

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.

TSA
  • 43
  • 5