The problem. Given a string s made only of the characters 0, 1 and 2, count the substrings that contain equally many 0s, 1s and 2s.
s = "0102010" -> 2 ("102" and "201")
s = "102100211" -> 5
s = "0011" -> 0 (no 2s at all)Members only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson