title: Longest Subarray Count 1S One Count 0S
signature: function longestSubarrayCount1SOneCount0S(arr, n) {
source_py: def longest_subarray_count_1s_one_count_0s(arr, n):
      um = {i: 0 for i in range(10)}
      sum = 0
      maxLen = 0
      for i in range(n):
          if (arr[i] == 0):
              sum += (- 1)
          else:
              sum += 1
          if (sum == 1):
              maxLen = (i + 1)
          elif (sum not in um):
              um[sum] = i
          if ((sum - 1) in um):
              if (maxLen < (i - um[(sum - 1)])):
                  maxLen = (i - um[(sum - 1)])
      return maxLen
source_cpp: int longest_subarray_count_1s_one_count_0s(vector<int> arr, int n) {
    unordered_map < int, int > um;
    int sum = 0, maxLen = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      sum += arr [ i ] == 0 ? - 1 : 1;
      if ( sum == 1 ) maxLen = i + 1;
      else if ( um . find ( sum ) == um . end ( ) ) um [ sum ] = i;
      if ( um . find ( sum - 1 ) != um . end ( ) ) {
        if ( maxLen < ( i - um [ sum - 1 ] ) ) maxLen = i - um [ sum - 1 ];
      }
    }
    return maxLen;
  }