CanvaOA #3
Counting Binary Substrings (Backend)
Estimated EasyJudge-ready
Topics (AI-labelled)Strings
Count all contiguous substrings that consist of exactly two runs, one of 0s and one of 1s, with equal lengths.
This site's standard I/O format and any supplementary ranges follow this problem's statement.
Input
A single line containing a binary string s, 5≤|s|≤500000; characters are only 0/1.
Output
Output the number of qualifying substrings.
Example 1
Input:
001101
Output:
4
Example 2
Input:
00110
Output:
3
Example 3
Input:
010101
Output:
5
Editorial
Loading solution…