title: Maximum Area Rectangle Picking Four Sides Array 1
signature: maximum_area_rectangle_picking_four_sides_array_1 <- 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(4L, 6L, 7L, 8L, 12L, 13L, 14L, 15L, 18L, 18L, 19L, 19L, 26L, 26L, 32L, 32L, 33L, 34L, 34L, 36L, 41L, 43L, 47L, 47L, 51L, 51L, 52L, 53L, 55L, 56L, 57L, 60L, 61L, 71L, 74L, 75L, 76L, 77L, 79L, 87L, 87L, 87L, 90L, 95L, 98L, 99L), 37L, 
          2397L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-64L, -72L, 6L, -62L, 54L, 14L, 28L, 60L, -96L, 14L, -32L, -2L, 80L, 8L, -56L, 68L, 86L, 64L, 86L, -12L, 82L), 12L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 27L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(99L, 7L, 14L, 50L, 94L, 24L, 79L, 13L, 19L, 29L, 22L, 2L, 77L, 36L, 38L, 18L, 51L, 15L, 99L, 52L, 17L, 77L, 22L, 54L), 15L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -92L, -86L, -84L, -84L, -80L, -70L, -70L, -68L, -64L, -64L, -48L, -46L, -24L, -22L, -20L, -8L, -8L, 0L, 0L, 4L, 8L, 8L, 22L, 28L, 36L, 46L, 50L, 52L, 54L, 60L, 62L, 66L, 70L, 80L, 84L, 86L, 94L, 96L, 96L), 25L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L), 12L, 
          1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(98L), 0L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-88L, -24L, 8L, 20L, -46L, 60L, 24L, 26L, 98L, 82L, -30L, 16L, 22L, -28L, 84L, 12L, 34L, 14L, -18L, -38L, -94L, -24L, 6L, 4L, -52L, -48L, 84L), 21L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 21L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(6L, 30L, 47L, 97L, 20L, 16L, 68L, 34L, 1L, 77L, 48L, 8L, 22L, 68L), 8L, 
          0L
      )))
  
  }
  
  main()
source_py: def maximum_area_rectangle_picking_four_sides_array_1(arr, n):
      s = []
      first = 0
      second = 0
      for i in range(n):
          if (arr[i] not in s):
              s.append(arr[i])
              continue
          if (arr[i] > first):
              second = first
              first = arr[i]
          elif (arr[i] > second):
              second = arr[i]
      return (first * second)
source_cpp: int maximum_area_rectangle_picking_four_sides_array_1(vector<int> arr, int n) {
    unordered_set < int > s;
    int first = 0, second = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( s . find ( arr [ i ] ) == s . end ( ) ) {
        s . insert ( arr [ i ] );
        continue;
      }
      if ( arr [ i ] > first ) {
        second = first;
        first = arr [ i ];
      }
      else if ( arr [ i ] > second ) second = arr [ i ];
    }
    return ( first * second );
  }