title: Longest Subarray Count 1S One Count 0S
signature: function longest_subarray_count_1s_one_count_0s(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;
  }
question_info.entry_fn_name: longest_subarray_count_1s_one_count_0s
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({6, 10, 31, 35}, 2, 1)
      print(string.format("TEST-0...%s",result))
  
      result = driver({4, 88, -72, 28, -54, 32, -34}, 6, 5)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 1, 1, 1, 1, 1, 1}, 4, 1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({39, 22, 15, 10, 34, 87, 46, 83, 74, 77, 61, 90, 43, 67, 64, 72, 92, 52, 68, 53, 67, 32, 82, 76, 76, 47, 74, 47, 8, 80, 85, 58, 75}, 26, 9)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-82, -58, -50, -30, -14, -4, -2, -2, 0, 22, 36, 58, 70, 80, 80, 82, 84, 90}, 14, 11)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1}, 7, 7)
      print(string.format("TEST-5...%s",result))
  
      result = driver({4, 11, 17, 21, 21, 22, 30, 31, 36, 37, 39, 40, 45, 46, 47, 48, 52, 53, 53, 60, 60, 65, 66, 66, 67, 67, 87, 88, 91, 97}, 29, 9)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-4, -60, -78, -50, 64, 18, 0, 76, 12, 86, -22}, 7, 6)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 3)
      print(string.format("TEST-8...%s",result))
  
      result = driver({4, 39, 50, 37, 71, 66, 55, 34, 1, 41, 34, 99, 69, 31}, 11, 9)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 1, "inputs": {"arr": [6, 10, 31, 35], "n": 2}}, {"idx": 1, "outputs": 5, "inputs": {"arr": [4, 88, -72, 28, -54, 32, -34], "n": 6}}, {"idx": 2, "outputs": 1, "inputs": {"arr": [0, 0, 0, 1, 1, 1, 1, 1, 1], "n": 4}}, {"idx": 3, "outputs": 9, "inputs": {"arr": [39, 22, 15, 10, 34, 87, 46, 83, 74, 77, 61, 90, 43, 67, 64, 72, 92, 52, 68, 53, 67, 32, 82, 76, 76, 47, 74, 47, 8, 80, 85, 58, 75], "n": 26}}, {"idx": 4, "outputs": 11, "inputs": {"arr": [-82, -58, -50, -30, -14, -4, -2, -2, 0, 22, 36, 58, 70, 80, 80, 82, 84, 90], "n": 14}}, {"idx": 5, "outputs": 7, "inputs": {"arr": [1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1], "n": 7}}, {"idx": 6, "outputs": 9, "inputs": {"arr": [4, 11, 17, 21, 21, 22, 30, 31, 36, 37, 39, 40, 45, 46, 47, 48, 52, 53, 53, 60, 60, 65, 66, 66, 67, 67, 87, 88, 91, 97], "n": 29}}, {"idx": 7, "outputs": 6, "inputs": {"arr": [-4, -60, -78, -50, 64, 18, 0, 76, 12, 86, -22], "n": 7}}, {"idx": 8, "outputs": 3, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 17}}, {"idx": 9, "outputs": 9, "inputs": {"arr": [4, 39, 50, 37, 71, 66, 55, 34, 1, 41, 34, 99, 69, 31], "n": 11}}]