Count substrings with equal number of consecutive 0s and 1s (like "0011","10","01","1100").

Input: s="00110011" → Output: 6 Input: s="10101" → Output: 4

Track previous group size and current group size. When group changes, pairs available = min(prev, curr).

public int countBinarySubstrings(String s) { int prev = 0, curr = 1, count = 0; for (int i = 1; i < s.length(); i++) { if (s.charAt(i) == s.charAt(i-1)) curr++; else { prev = curr; curr = 1; } if (prev >= curr) count++; } return count; }