RubrikOA #1
Count Binary Substrings
Estimated EasyJudge-ready
Topics (AI-labelled)StringsTwo Pointers
Count all contiguous substrings in which the number of 0s equals the number of 1s and that consist of exactly one block of identical characters immediately followed by one block of the other character. Identical content at different positions is counted separately.
Input
One line containing a non-empty binary string s. This site adds 1≤|s|≤200000.
Output
Output the number of qualifying substrings as an exact decimal integer (an integer type of at least 64 bits is required).
Example 1
Input:
00110011
Output:
6
Example 2
Input:
01
Output:
1
Example 3
Input:
0000
Output:
0
Editorial
Loading solution…