Skip to content

The Love Letter Mystery Details

Sushant Jhingan edited this page Sep 27, 2018 · 2 revisions

James found a love letter that his friend Harry has written to his girlfriend. James is a prankster, so he decides to meddle with the letter. He changes all the words in the letter into palindromes.

To do this, he follows two rules:

  1. He can only reduce the value of a letter by $1$, i.e. he can change d to c, but he cannot change c to d or d to b.
  2. The letter a may not be reduced any further.

Each reduction in the value of any letter is counted as a single operation. Find the minimum number of operations required to convert a given string into a palindrome.

For example, given the string $s = \texttt{cde}$, the following two operations are performed: cdecddcdc.

Function Description

Complete the theLoveLetterMystery function in the editor below. It should return the integer representing the minimum number of operations needed to make the string a palindrome.

theLoveLetterMystery has the following parameter(s):

  • s: a string

INPUT:

4 abc abcba abcd cba

Clone this wiki locally