| Codeforces Round 1122 (Div. 3) |
|---|
| Finished |
You are given a binary string$$$^{\text{∗}}$$$ $$$s$$$ of length $$$n$$$.
You may perform the following operation any number of times (possibly zero):
Note that the bitwise AND or bitwise OR of a single element is equal to the element itself.
Your goal is to make $$$s$$$ sorted in non-decreasing order$$$^{\text{†}}$$$.
Find the minimum number of operations required to sort $$$s$$$ in non-decreasing order.
$$$^{\text{∗}}$$$A binary string only contains characters $$$\texttt{0}$$$ and $$$\texttt{1}$$$.
$$$^{\text{†}}$$$If $$$s$$$ is in non-decreasing order, then $$$s_1 \leq s_2 \leq \ldots \leq s_n$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the binary string $$$s$$$.
The second line of each test case contains the binary string $$$s$$$ of length $$$n$$$. Each character of $$$s$$$ is either 0 or 1.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print a single integer — the minimum number of operations required to sort $$$s$$$ in non-decreasing order.
640011410005010008010011017010101070111101
031231
In the first test case, the string is already sorted, so no operations are required.
In the second test case, we can use bitwise OR to change the last three characters to 1, obtaining 1111 in $$$3$$$ operations.
| Name |
|---|


