You are given a string s consisting of lowercase English letters.
You can perform the following operations any number of times (including zero) and in any order:
i and replace s[i] with the next lowercase English letter. The letter after 'z' is 'a'.Return the minimum number of operations required to make s a palindrome.
A palindrome is a string that reads the same forward and backward.
Example 1:
Input: s = "abc"
Output: 2
Explanation:
One optimal solution:"abc" -> "bca".'a' to 'b': "bca" -> "bcb"."bcb" is a palindrome. Thus, the answer is 2.Example 2:
Input: s = "yb"
Output: 3
Explanation:
"yb" -> "zb" -> "ab" -> "bb"."bb" is a palindrome. Thus, the answer is 3.Constraints:
2 <= s.length <= 2000s consists only of lowercase English letters.It is enough to consider performing r left rotations, where 0 <= r < s.length. The increment operations can then be considered independently for each mirrored pair.
For two letters a and b, the minimum number of increments needed to make them equal is min(abs(a - b), 26 - abs(a - b)).
Try every rotation. For each one, sum this cost over all mirrored pairs and add the number of rotations. This gives an O(n^2) solution.
"abc"
"yb"