DellOA #2
Count Binary Substrings
Estimated EasyJudge-ready
Topics (AI-labelled)StringsTwo Pointers
Count the contiguous substrings in which the numbers of 0s and 1s are equal and each character forms a single contiguous block. Identical text at different positions is counted separately.
Input
One line containing a binary string of only 0 and 1. The original upper bound on the length is 100000, and no lower bound is given; this site keeps the empty string (an empty line) as valid.
Output
Output a single integer, the answer.
Example 1
Input:
011001
Output:
4
Example 2
Input:
00110011
Output:
6
Example 3
Input:
Output:
0
Example notes
The outputs of the three public examples are, in order: 4; 6; 0. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…