#C6632. Minimum Operations to Palindrome
Minimum Operations to Palindrome
Minimum Operations to Palindrome
You are given a string s consisting of lowercase English letters. Your task is to determine the minimum number of operations required to transform the string into a palindrome. In one operation, you can change one character of the string to any other character. Note that you only need to change one end of a mismatched pair (i.e. for indices i and n-i-1 if s[i] != s[n-i-1]) to make the string a palindrome.
Formally, let n be the length of the string. Considering all indices 0 ≤ i < n/2, if s[i] != s[n-i-1] then an operation is required. Therefore, the answer is the number of such mismatched pairs.
Examples:
- For
s = "abc"
, the answer is 1. - For
s = "aabb"
, the answer is 2. - For
s = "racecar"
, the answer is 0.
inputFormat
The input consists of a single line containing the string s (which may be empty) composed of lowercase English letters.
Input Format:
s
outputFormat
Output a single integer representing the minimum number of operations required to transform the string into a palindrome.
Output Format:
answer## sample
abc
1