title: Maximum Area Rectangle Picking Four Sides Array
signature: function maximum_area_rectangle_picking_four_sides_array(arr, n)
source_py: def maximum_area_rectangle_picking_four_sides_array(arr, n):
      arr.sort(reverse=True)
      dimension = [0, 0]
      i = 0
      j = 0
      while ((i < (n - 1)) and (j < 2)):
          if (arr[i] == arr[(i + 1)]):
              dimension[j] = arr[i]
              j += 1
              i += 1
          i += 1
      return (dimension[0] * dimension[1])
source_cpp: int maximum_area_rectangle_picking_four_sides_array(vector<int> arr, int n) {
    sort(arr.begin(), arr.end(), greater < int > ( ) );
    int dimension [ 2 ] = {
      0, 0 };
      for ( int i = 0, j = 0;
      i < n - 1 && j < 2;
      i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ];
      return ( dimension [ 0 ] * dimension [ 1 ] );
    }
question_info.entry_fn_name: maximum_area_rectangle_picking_four_sides_array
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({99, 96, 95, 95, 92, 84, 83, 82, 81, 74, 72, 68, 67, 52, 51, 51, 49, 47, 44, 40, 36, 25, 24, 17, 16, 14, 12, 11, 9, 8, 6, 5, 1}, 27, 4845)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-32, -54, -82, -92}, 2, 0)
      print(string.format("TEST-1...%s",result))
  
      result = driver({1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 15, 1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({99, 96, 96, 94, 68, 65, 62, 60, 45, 44, 30, 26, 17, 17, 16, 15, 2}, 8, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver({98, 94, 82, 82, 74, 66, 66, 56, 54, 46, 16, -28, -34, -42, -50, -52, -78, -82, -88}, 15, 5412)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 18, 1)
      print(string.format("TEST-5...%s",result))
  
      result = driver({97, 96, 93, 87, 85, 85, 75, 68, 65, 65, 64, 63, 62, 58, 56, 52, 49, 44, 43, 38, 33, 30, 29, 28, 27, 25, 24, 23, 14, 14, 13, 10, 8, 8, 8, 6, 1}, 20, 5525)
      print(string.format("TEST-6...%s",result))
  
      result = driver({78, 78, 76, 70, 60, 54, 50, 32, 16, 16, 6, -6, -20, -56, -64, -68, -70, -90, -90, -92}, 19, 1248)
      print(string.format("TEST-7...%s",result))
  
      result = driver({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 30, 1)
      print(string.format("TEST-8...%s",result))
  
      result = driver({94, 94, 94, 90, 84, 82, 75, 71, 57, 55, 53, 51, 51, 43, 35, 31, 30, 29, 22, 18, 14, 10, 7, 5, 4}, 22, 4794)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 4845, "inputs": {"arr": [99, 96, 95, 95, 92, 84, 83, 82, 81, 74, 72, 68, 67, 52, 51, 51, 49, 47, 44, 40, 36, 25, 24, 17, 16, 14, 12, 11, 9, 8, 6, 5, 1], "n": 27}}, {"idx": 1, "outputs": 0, "inputs": {"arr": [-32, -54, -82, -92], "n": 2}}, {"idx": 2, "outputs": 1, "inputs": {"arr": [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "n": 15}}, {"idx": 3, "outputs": 0, "inputs": {"arr": [99, 96, 96, 94, 68, 65, 62, 60, 45, 44, 30, 26, 17, 17, 16, 15, 2], "n": 8}}, {"idx": 4, "outputs": 5412, "inputs": {"arr": [98, 94, 82, 82, 74, 66, 66, 56, 54, 46, 16, -28, -34, -42, -50, -52, -78, -82, -88], "n": 15}}, {"idx": 5, "outputs": 1, "inputs": {"arr": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "n": 18}}, {"idx": 6, "outputs": 5525, "inputs": {"arr": [97, 96, 93, 87, 85, 85, 75, 68, 65, 65, 64, 63, 62, 58, 56, 52, 49, 44, 43, 38, 33, 30, 29, 28, 27, 25, 24, 23, 14, 14, 13, 10, 8, 8, 8, 6, 1], "n": 20}}, {"idx": 7, "outputs": 1248, "inputs": {"arr": [78, 78, 76, 70, 60, 54, 50, 32, 16, 16, 6, -6, -20, -56, -64, -68, -70, -90, -90, -92], "n": 19}}, {"idx": 8, "outputs": 1, "inputs": {"arr": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "n": 30}}, {"idx": 9, "outputs": 4794, "inputs": {"arr": [94, 94, 94, 90, 84, 82, 75, 71, 57, 55, 53, 51, 51, 43, 35, 31, 30, 29, 22, 18, 14, 10, 7, 5, 4], "n": 22}}]