Company: IBM
Difficulty: medium
Binary String Substring Count A binary string is a string consisting only of 0s and 1s. A substring is a contiguous group of characters within a string. Given a binary string, find the number of substrings that contain an equal number of 0s and 1s and all the 0s and 1s are grouped together. Note that duplicate substrings are also counted in the answer. For example, \'0011\' has two overlapping substrings that meet the criteria: \'0011\' and \'01\' . Input Format The input consists of a single binary string s . Output Format Return the number of valid substrings that meet the criteria. Constraints 1 ≤ |s| ≤ 100 , where |s| is the length of the string. Examples Input: s = \"011001\" Output: 4 The substrings \"01\", \"10\", \"1100\", and \"01\" have equal numbers of 0s and 1s with all 0s and 1s grouped consecutively. Hence, the answer is 4.