#GYM104669D. Binary Sorting
Binary Sorting
Description
Given a binary string of length $n$ ($1 \le n \le 2 \cdot 10^5$). You can peform and operation which involves choosing $l$ and $r$ ($1 \le l \le r \le n$) and reversing the substring from $l$ to $r$. What is the minimum number of moves to sort the binary string (all $0$s should be before all $1$s)?
First line contains a single number $n$ ($1 \le n \le 2 \cdot 10^5$).
Second line contains a string with $n$ characters, each either $0$ or $1$.
Output a single number $X$, the minimum number of moves to sort the inputted binary string.
Input
First line contains a single number $n$ ($1 \le n \le 2 \cdot 10^5$).
Second line contains a string with $n$ characters, each either $0$ or $1$.
Output
Output a single number $X$, the minimum number of moves to sort the inputted binary string.
5
11010
2
Note
We can first choose the range ($1, 5$), giving us the string $01011$ after the reversing operation. We then choose the range $(2, 3)$, giving us $00111$ which is fully sorted. There is no way to get to a fully sorted binary string in less operations.