signal of zeros and ones. Call a piece (a contiguous substring) a balanced block if it consists of a run of zeros and a run of ones of the same length, in either order: zeros first and then ones, or the other way round. For example, "000111" and "10" are balanced blocks, while "0101" and "0011100" are not.
Count how many pieces of signal are balanced blocks. Pieces with the same content at different positions are counted separately.signal="0011100" → 4
The fitting pieces are "01", "0011", "10" and "1100", four in total. "001110" does not count: it has three 1s and only two 0s.
signal="1010" → 3
Every adjacent pair of different characters is a piece of its own: "10", "01", "10".
signal="1111" → 0
There are no zeros at all, so nothing fits.
signal[i] is '0' or '1'signal="0011100"
4
Run checks the first 3 tests in your browser. Submit checks all 161 tests on the server, hidden ones included.