title: Maximum Area Rectangle Picking Four Sides Array
signature: maximum_area_rectangle_picking_four_sides_array <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(99L, 96L, 95L, 95L, 92L, 84L, 83L, 82L, 81L, 74L, 72L, 68L, 67L, 52L, 51L, 51L, 49L, 47L, 44L, 40L, 36L, 25L, 24L, 17L, 16L, 14L, 12L, 11L, 9L, 8L, 6L, 5L, 1L), 27L, 
          4845L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-32L, -54L, -82L, -92L), 2L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), 15L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(99L, 96L, 96L, 94L, 68L, 65L, 62L, 60L, 45L, 44L, 30L, 26L, 17L, 17L, 16L, 15L, 2L), 8L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(98L, 94L, 82L, 82L, 74L, 66L, 66L, 56L, 54L, 46L, 16L, -28L, -34L, -42L, -50L, -52L, -78L, -82L, -88L), 15L, 
          5412L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), 18L, 
          1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(97L, 96L, 93L, 87L, 85L, 85L, 75L, 68L, 65L, 65L, 64L, 63L, 62L, 58L, 56L, 52L, 49L, 44L, 43L, 38L, 33L, 30L, 29L, 28L, 27L, 25L, 24L, 23L, 14L, 14L, 13L, 10L, 8L, 8L, 8L, 6L, 1L), 20L, 
          5525L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(78L, 78L, 76L, 70L, 60L, 54L, 50L, 32L, 16L, 16L, 6L, -6L, -20L, -56L, -64L, -68L, -70L, -90L, -90L, -92L), 19L, 
          1248L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), 30L, 
          1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(94L, 94L, 94L, 90L, 84L, 82L, 75L, 71L, 57L, 55L, 53L, 51L, 51L, 43L, 35L, 31L, 30L, 29L, 22L, 18L, 14L, 10L, 7L, 5L, 4L), 22L, 
          4794L
      )))
  
  }
  
  main()
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 ] );
    }