Amazon Online Assessment 2021 (OA) - Counting Binary Substrings
In the vibrant world of self-publishing digital books, there's an intriguing new feature being developed that will help authors explore the usage of strings of text in various ways. Focusing on substrings, these are clusters of characters that are continuously found within a string; to illustrate, all the substrings of abc would be [a, b, c, ab, bc, abc].
Another interesting task to grapple with involves binary numbers, which are numbers represented only by 0s and 1s. The challenge is to determine the total count of substrings that comply with two specific rules:
-
The 0s and 1s must be grouped together, meaning they should appear side by side. This could look something like 01, 10, 0011, 1100, 000111, and so forth.
-
The number of 0s and the number of 1s in the substring must be equal; if there are two 0s, there should also be two 1s, and so on.
Relevant Amazon OA Problems:
s = 001101
4
5<=|s|<=5*10^5- each
s[i]is either '0' or '1'