FastPrepFastPrep
Problem Brief

Count Equal Binary Substrings

OA

Count the number of substrings in a binary string that contain an equal number of 0s and 1s, where all 0s and 1s are grouped together. Duplicate substrings are counted in the total.

A binary string consists only of 0s and 1s, and a substring is a contiguous group of characters within the string.

Function Description

Complete the function oneSubstringCount in the editor within the following parameter(s):

  • s: a binary string

Returns

int: the number of substrings that meet the criteria

Endless gratitude to a dear old friend whose generosity in sharing the source made all the difference. 🌸

1Example 1

Input
s = "011001"
Output
4
Explanation
The qualifying substrings are "01", "10", "1100", and "01", giving a total of 4. Note that "0110" has equal 0s and 1s but is not counted because the 0s and 1s are not grouped together.
public int oneSubstringCount(String s) {
  // write your code here
}
Input

s

"011001"

Output

4

Sign in to submit your solution.