@siddharth2000 Oh sorry.

My approach wasn’t very elegant.

There are 3 stages, to find all possible ways to select substring

- 0011
- 00110011
- 001100110011

For 1) I calculated at each position of the binary string, the no. of 0011 ending at that index. Then added the values at each index

For 2) In addition to what I did for 1), I calculated at each position of the binary string, the no. of 0011 starting at that index.

Now, at each index, multiplied no. of 0011 ending at that index, and no. of 0011 starting at the next index. Added up.

For 3), not too clear to put it in black and white, since the test cases could have been more complicated,

Find the index at which the first 0011 ends.

Find the index at which the last 0011 starts.

Now look at the middle elements, see how many 0011 you can get. This is your answer for stage 3.

Let me know if there’s any flaw. I also most likely made careless calculation mistakes while doing the above.