How to approach this question?
394

A perfect string is a string in which the absolute difference between adjacent characters is equal to 2, 3 or 4. For example, if the position of the characters 'd' and 'g' is 4 and 7 respectively, then the absolute difference between their positions is 3. Convert a simple string into a perfect string by using the minimum amount of time. The time to change one character to another takes the same amount of time that is equal to the absolute difference between the characters.

You need to convert string S into a perfect string by using the minimum amount of time.
Note: The string contains all lowercase characters

Input:
String S

Output:
Print the minimum changes that are required to modify the string S into a perfect string

Sample Input
abcdef

Sample Output
5

Explanation
One string with minimum cost is "acaceg" . The cost to convert abcdef to "acaceg" is 5

Comments (2)