Easy Solution , must check

int Solution::solve(vector &v) {
map< int , int> mp;
int sum=0,ans=INT_MIN;
mp[0]=-1;
for( int i=0; i<v.size(); i++){
sum+= v[i] == 0 ? -1 :1 ;
if(mp.find(sum) == mp.end()){
mp[sum]=i;
}
if( mp.find(sum-1)!=mp.end()){
ans=max(ans, i-mp[sum-1]);
}
}
return ans;
}

Click here to start solving coding interview questions