title: Find Largest D In Array Such That A B C D
signature: def findLargestDInArraySuchThatABCD(s: 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(s: List[Int], n: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(s, n),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        List(8, 12, 14, 15, 16, 20, 27, 28, 29, 30, 35, 41, 46, 51, 53, 55, 55, 58, 63, 64, 72, 73, 75, 75, 75, 82, 82, 86, 89, 91, 92, 94, 95, 95, 97, 97, 98), 24, 
        75    
      )}")   
  
  
      println(s"TEST-1...${driver(
        List(-96, -82, -62, -58, -56, -50, -44, -44, -40, -28, -22, -20, -12, -2, 10, 26, 34, 42, 48, 74, 86, 92), 19, 
        48    
      )}")   
  
  
      println(s"TEST-2...${driver(
        List(0, 0, 0, 0, 0, 0, 0, 1, 1, 1), 8, 
        0    
      )}")   
  
  
      println(s"TEST-3...${driver(
        List(10, 10, 47, 54, 55, 58, 65, 66, 67, 77, 84), 5, 
        -1    
      )}")   
  
  
      println(s"TEST-4...${driver(
        List(-46, -28, -20, -18, 4, 8, 18, 38, 90, 90), 6, 
        -1    
      )}")   
  
  
      println(s"TEST-5...${driver(
        List(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 35, 
        1    
      )}")   
  
  
      println(s"TEST-6...${driver(
        List(11, 13, 14, 21, 26, 28, 36, 39, 41, 42, 43, 44, 49, 49, 57, 58, 59, 59, 63, 64, 67, 69, 70, 75, 78, 79, 83, 83, 86, 91, 92, 93, 96, 96, 96, 97), 30, 
        91    
      )}")   
  
  
      println(s"TEST-7...${driver(
        List(-88, -82, -82, -76, -70, -66, -62, -56, -48, -48, -32, -30, -18, -16, 0, 4, 34, 38, 46, 46, 50, 52, 54, 54, 62, 74, 76, 78, 96), 16, 
        -30    
      )}")   
  
  
      println(s"TEST-8...${driver(
        List(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 17, 
        1    
      )}")   
  
  
      println(s"TEST-9...${driver(
        List(4, 5, 6, 9, 11, 14, 18, 20, 21, 25, 33, 49, 55, 56, 58, 61, 66, 66, 68, 74, 74, 87, 92, 99), 23, 
        92    
      )}")   
  
  }
  
source_py: def find_largest_d_in_array_such_that_a_b_c_d(S, n):
      found = False
      S.sort()
      for i in range((n - 1), (- 1), (- 1)):
          for j in range(0, n):
              if (i == j):
                  continue
              for k in range((j + 1), n):
                  if (i == k):
                      continue
                  for l in range((k + 1), n):
                      if (i == l):
                          continue
                      if (S[i] == ((S[j] + S[k]) + S[l])):
                          found = True
                          return S[i]
      if (found == False):
          return (- 1)
source_cpp: int find_largest_d_in_array_such_that_a_b_c_d(vector<int> S, int n) {
    bool found = false;
    sort(S.begin(), S.end());
    for ( int i = n - 1;
    i >= 0;
    i -- ) {
      for ( int j = 0;
      j < n;
      j ++ ) {
        if ( i == j ) continue;
        for ( int k = j + 1;
        k < n;
        k ++ ) {
          if ( i == k ) continue;
          for ( int l = k + 1;
          l < n;
          l ++ ) {
            if ( i == l ) continue;
            if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {
              found = true;
              return S [ i ];
            }
          }
        }
      }
    }
    if ( found == false ) return INT_MIN;
  }