Tap here to switch tabs
Problem
Submissions

Problem: Count Binary Substrings

Count Binary Substrings asks you to count non-empty substrings of a binary string with equal zeros and ones, with each character grouped consecutively. Count occurrences separately.

Statement

Given a binary string s, return the count of non-empty substrings that satisfy both of the following conditions:

  • The substring contains an equal number of '0's and '1's.

  • All '0's and all '1's within the substring are grouped consecutively (i.e., no interleaving of the two characters).

Substrings that appear multiple times are counted once for each occurrence.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is either '0' or '1'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Binary Substrings

Count Binary Substrings asks you to count non-empty substrings of a binary string with equal zeros and ones, with each character grouped consecutively. Count occurrences separately.

Statement

Given a binary string s, return the count of non-empty substrings that satisfy both of the following conditions:

  • The substring contains an equal number of '0's and '1's.

  • All '0's and all '1's within the substring are grouped consecutively (i.e., no interleaving of the two characters).

Substrings that appear multiple times are counted once for each occurrence.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s[i] is either '0' or '1'