This can be solved using Hashing in O(N).
- Take 2 variables to store count of 0 and count of 1.
- Take diff=count1-count0
- Hash diff along with the position or index where we obtain the diff.
- This is continued every time a new diff that is not already present in the hash is obtained.
- If hash already has diff, then if we remove the subarray with that diff, we will obtain a subarray with diff =0. This fact is used now.