#K37192. Minimum Flips to Make Binary String Alternating
Minimum Flips to Make Binary String Alternating
Minimum Flips to Make Binary String Alternating
Given an integer \( n \) and a binary string of length \( n \) consisting of characters '0' and '1', your task is to determine the minimum number of flips required to transform the binary string into an alternating binary string. An alternating binary string is one where no two adjacent characters are the same.
There are two possible alternating patterns of length \( n \):
- \( 010101\ldots \)
- \( 101010\ldots \)
You should compute the number of mismatches between the given binary string and both alternating patterns, and output the minimum of the two counts.
inputFormat
The input consists of two lines:
- The first line contains an integer \( n \) representing the length of the binary string.
- The second line contains the binary string of length \( n \) composed only of characters '0' and '1'.
You may assume that \( 1 \leq n \leq 10^5 \).
outputFormat
Output a single integer on a new line, which is the minimum number of flips needed to convert the input binary string into one of the two alternating binary strings.
## sample5
01010
0
</p>