## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## [Solution] Sort the String CodeChef Solution | Codechef Solution

You have a binary string $S$ of length $N$. In one operation you can select a substring of $S$ and reverse it. For example, on reversing the substring $S\left[2,4\right]$ for $S=11000$, we change $11000\to 10010$.

Find the minimum number of operations required to sort this binary string.
It can be proven that the string can always be sorted using the above operation finite number of

Solution Click Below:-  👉
👇👇👇👇👇

times.

### Input Format

• The first line of input will contain a single integer $T$, denoting the number of test cases.
• Each test case consists of $2$ lines of input.
• The first line of each test case contains a single integer $N$ — the length of the binary string.
• The second line of each test case contains a binary string $S$ of length $N$.

### Output Format

For each test case, output on a new line — the minimum number of operations requi

Counting Words CodeChef Solution

MATH1 Enrolment CodeChef Solution

Group Assignment CodeChef Solution

Army Training CodeChef Solution

Sort the String CodeChef Solution

Prime Xor CodeChef Solution

Vowel Anxiety CodeChef Solution

Array sorting CodeChef Solution

red to sort the binary string.

### Constraints

• $1\le T\le 2\cdot {10}^{5}$
• $1\le N\le 2\cdot {10}^{5}$
• Sum of $N$ over all test cases does not exceed ${10}^{6}$.
• String $S$ consists of only '$0$'s and '$1$'s.