#K62042. Minimum Operations to Uniform Binary String

    ID: 31443 Type: Default 1000ms 256MiB

Minimum Operations to Uniform Binary String

Minimum Operations to Uniform Binary String

You are given a binary string of length n consisting only of characters '0' and '1'. Your task is to determine the minimum number of operations required to make the string uniform, i.e. all characters in the string are identical (either all '0's or all '1's).

In one operation, you may flip a single character (change a '0' to a '1' or vice versa). The optimal strategy is to flip the lesser frequent character. Formally, if \(c_0\) is the number of zeros and \(c_1 = n - c_0\) is the number of ones, the answer is \(\min(c_0, c_1)\).

Examples:

  • For \(n = 5\) and the binary string "01100", the minimum number of operations is \(2\).
  • For \(n = 7\) and the binary string "1111111", the minimum number of operations is \(0\).
  • For \(n = 6\) and the binary string "100110", the minimum number of operations is \(3\).

inputFormat

The input is given via standard input as follows:

The first line contains an integer n representing the length of the binary string.
The second line contains a binary string of length n composed of characters '0' and '1'.

outputFormat

Output a single integer representing the minimum number of operations required to make the binary string uniform.

## sample
5
01100
2