#C8481. Minimum Operations to Make a Palindrome

    ID: 52468 Type: Default 1000ms 256MiB

Minimum Operations to Make a Palindrome

Minimum Operations to Make a Palindrome

Given a string S of length N, determine the minimum number of operations required to transform it into a palindrome. An operation is defined as changing one character so that both halves of the string become mirror images of each other. Mathematically, for each index i such that \(0 \le i < \lfloor N/2 \rfloor\), if \(S[i] \neq S[N-i-1]\), one operation is needed. The answer is the total count of such mismatched pairs.

Examples:

  • For S = "abca" with N = 4, the answer is 1.
  • For S = "aaa" with N = 3, the answer is 0 because the string is already a palindrome.

inputFormat

The input consists of two lines. The first line contains an integer N, representing the length of the string. The second line contains the string S, composed of lowercase alphabetical characters.

outputFormat

Output a single integer which is the minimum number of operations required to transform the given string into a palindrome.## sample

4
abca
1

</p>