← Questions

Count binary substrings

0
MicrosoftCodingLast asked Aug 2026

Count the non-empty substrings of a binary string that have the same number of 0s and 1s, with all the 0s together and all the 1s together. Solve it in one pass by comparing lengths of consecutive runs.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding