title: Maximum Area Rectangle Picking Four Sides Array
signature: def maximumAreaRectanglePickingFourSidesArray(arr: List[Int], n: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(arr: List[Int], n: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-1...${driver(
        List(-32, -54, -82, -92), 2, 
        0    
      )}")   
  
  
      println(s"TEST-2...${driver(
        List(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 15, 
        1    
      )}")   
  
  
      println(s"TEST-3...${driver(
        List(99, 96, 96, 94, 68, 65, 62, 60, 45, 44, 30, 26, 17, 17, 16, 15, 2), 8, 
        0    
      )}")   
  
  
      println(s"TEST-4...${driver(
        List(98, 94, 82, 82, 74, 66, 66, 56, 54, 46, 16, -28, -34, -42, -50, -52, -78, -82, -88), 15, 
        5412    
      )}")   
  
  
      println(s"TEST-5...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-6...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-7...${driver(
        List(78, 78, 76, 70, 60, 54, 50, 32, 16, 16, 6, -6, -20, -56, -64, -68, -70, -90, -90, -92), 19, 
        1248    
      )}")   
  
  
      println(s"TEST-8...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-9...${driver(
        List(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    
      )}")   
  
  }
  
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 ] );
    }