Back to problems

Grouped Binary Substrings

Algorithm · JPMorgan · Medium

Requirements You are given a string s made exclusively of the characters 0 and 1. Implement: Return how many substrings meet both of these requirements: The substring contains the same number of 0 characters and 1 characters. Its characters form exactly two contiguous runs, with one run of 0s and one run of 1s. For instance, shapes such as 0000111, 1110000, 01, and 10 are eligible when their two runs have equal lengths. Examples Example 1 There are four consecutive runs of…

Checking your access…