What's the optimal solution of this problem


Multiplication of count of 0's and 1's.

1 Like

but why we did that… can you explain ?

Choose any 0 and any 1, you will be able to construct a substring from them as they can definitely not be in the same position and it does not matter if 1 comes at the start or 0 comes at the start. Thus if there are m 1s and n 0s, you can choose the 1s in m ways and 0s in n ways making the answer m*n