Count Binary Substrings Problem

Count Binary Substrings Problem — ExecCode Easy DSA Practice

Solve the Count Binary Substrings problem on ExecCode. Free online easy DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in these substrings are grouped consecutively. Your task is to substrings that occur multiple times are counted the number of times they occur. Return the required answer exactly as shown in the examples.

Examples

Input {"s": "00110011"}; Output 6. Input {"s": "10101"}; Output 4. Input {"s": "10"}; Output 1

Constraints

1 <= s.length <= 10^5 s[i] is either '0' or '1'.

Practice Count Binary Substrings free on ExecCode. Browse DSA problems, topic map, and placement guides.