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:
s.length
s[i] is either '0' or '1'
The key insight is that valid substrings always straddle the boundary between two consecutive groups of identical characters. For any such boundary, the number of valid substrings that can be formed equals the minimum of the sizes of the two adjacent groups. For example, if there are
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:
s.length
s[i] is either '0' or '1'
The key insight is that valid substrings always straddle the boundary between two consecutive groups of identical characters. For any such boundary, the number of valid substrings that can be formed equals the minimum of the sizes of the two adjacent groups. For example, if there are