line contains only the letters a and b. We want no b to appear to the left of any a, so that the string reads "all the as, then all the bs" (either part may be empty).
The only thing you may do is delete characters; the rest keep their order. Return the smallest number of deletions that brings the string into that shape.line="babab" → 2
Delete the first two bs to get aab, or delete both as to get bbb. Either way two deletions are enough, and one is not.
line="aabba" → 1
Removing the last a is enough: aabb remains.
line="aaabbb" → 0
The string is already in order, so nothing has to go.
line is a or bline="babab"
2
Run checks the first 3 tests in your browser. Submit checks all 193 tests on the server, hidden ones included.