Largest subarray with 0 and 1 ;

https://hack.codingblocks.com/contests/c/509/1302

how to solve this

This can be solved using Hashing in O(N).

  1. Take 2 variables to store count of 0 and count of 1.
  2. Take diff=count1-count0
  3. Hash diff along with the position or index where we obtain the diff.
  4. This is continued every time a new diff that is not already present in the hash is obtained.
  5. 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.