ret_arr_with_max_0_1.cpp
/*You are required to complete this method*/
You are required to complete this method
You are required to complete this method
int maxLen(int arr[], int n)
{
    for(int i = 0; i < n; ++i)
        arr[i] = (arr[i] == 0) ? -1 : 1;
    int sum = 0, maxm = 0;
    unordered_map<int, int> um;
    for(int i = 0; i < n; ++i){
        sum += arr[i];
        if(sum == 0)
            maxm = max(maxm, i + 1);
        if(um.find(sum + n) != um.end())
            maxm = max(maxm, i - um[sum + n]);
        else
            um[sum + n] = i;
    }
    return maxm;
}
int maxLen ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; ++ i ) arr [ i ] = ( arr [ i ] == 0 ) ? -1 : 1 ; int sum = 0 , maxm = 0 ; unordered_map < int , int > um ; for ( int i = 0 ; i < n ; ++ i ) { sum += arr [ i ] ; if ( sum == 0 ) maxm = max ( maxm , i + 1 ) ; if ( um . find ( sum + n ) != um . end ( ) ) maxm = max ( maxm , i - um [ sum + n ] ) ; else um [ sum + n ] = i ; } return maxm ; }
You are required to complete this method
You are required to complete this method
//Your code here