Counting Binary Substrings (Backend)
A substring is a group of contiguous characters in a string. For instance, all substrings of abc are [a, b, c, ab, bc, abc].
Given a binary representation of a number, determine the total number of substrings present that match the following conditions:
As an example, consider the string 001101. The 4 substrings matching the two conditions include [0011, 01, 10, 01]. Note that 01 appears twice, from indices 1-2 and 4-5. There are other substrings, e.g. 001 and 011 that match the first condition but not the second.
Complete the function counting in the editor 🐸👉.
Returns
int: the number of substrings of s that satisfy the two conditions
1Example 1
Constraints
Limits and guarantees your solution can rely on.
5 ≤ |s| ≤ 5 x 105each s[i] is either '0' or '1'