Balanced Prefix
Print the length of the longest PREFIX containing equally many 0s and 1s (0 if none).
Input: one line with a binary string.
Output: the longest balanced prefix length.
Constraints:
- 1 ≤ |S| ≤ 105
Sample Tests
Input 1
110100
Output 1
6
Input 2
111
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.