You have an array of 0s and 1s and you want to output all the
intervals (i, j) where the number of 0s and numbers of 1s are equal.
Example
pos = 0 1 2 3 4 5 6 7 8
arr = 0 1 0 0 1 1 1 1 0
One interval is (0, 1) because there the number of 0 and 1 are equal.
There are many other intervals, find
Replce all 0's with -1
-1 1 -1 -1 1 1 1 1 -1
perform the following operation
a[i] = a[i-1] + a[i] for i = 1 to n-1
-1 0 -1 -2 -1 0 1 2 1
consider first element as 0
0 -1 0 -1 -2 -1 0 1 2 1
hash all these values to an array of size 2n+1 as sum will lie between -n to
n
where for 2 ij value hash to