title: Find Largest D In Array Such That A B C D
signature: find_largest_d_in_array_such_that_a_b_c_d <- function(s, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(s, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(s, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(8L, 12L, 14L, 15L, 16L, 20L, 27L, 28L, 29L, 30L, 35L, 41L, 46L, 51L, 53L, 55L, 55L, 58L, 63L, 64L, 72L, 73L, 75L, 75L, 75L, 82L, 82L, 86L, 89L, 91L, 92L, 94L, 95L, 95L, 97L, 97L, 98L), 24L, 
          75L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-96L, -82L, -62L, -58L, -56L, -50L, -44L, -44L, -40L, -28L, -22L, -20L, -12L, -2L, 10L, 26L, 34L, 42L, 48L, 74L, 86L, 92L), 19L, 
          48L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), 8L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(10L, 10L, 47L, 54L, 55L, 58L, 65L, 66L, 67L, 77L, 84L), 5L, 
          -1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-46L, -28L, -20L, -18L, 4L, 8L, 18L, 38L, 90L, 90L), 6L, 
          -1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 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, 1L, 1L, 1L), 35L, 
          1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(11L, 13L, 14L, 21L, 26L, 28L, 36L, 39L, 41L, 42L, 43L, 44L, 49L, 49L, 57L, 58L, 59L, 59L, 63L, 64L, 67L, 69L, 70L, 75L, 78L, 79L, 83L, 83L, 86L, 91L, 92L, 93L, 96L, 96L, 96L, 97L), 30L, 
          91L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-88L, -82L, -82L, -76L, -70L, -66L, -62L, -56L, -48L, -48L, -32L, -30L, -18L, -16L, 0L, 4L, 34L, 38L, 46L, 46L, 50L, 52L, 54L, 54L, 62L, 74L, 76L, 78L, 96L), 16L, 
          -30L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 17L, 
          1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(4L, 5L, 6L, 9L, 11L, 14L, 18L, 20L, 21L, 25L, 33L, 49L, 55L, 56L, 58L, 61L, 66L, 66L, 68L, 74L, 74L, 87L, 92L, 99L), 23L, 
          92L
      )))
  
  }
  
  main()
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;
  }