title: Find Largest D In Array Such That A B C D 1
signature: find_largest_d_in_array_such_that_a_b_c_d_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(1L, 1L, 5L, 7L, 10L, 35L, 35L, 45L, 49L, 50L, 57L, 58L, 60L, 64L, 69L, 83L, 83L, 87L, 88L, 89L, 93L, 94L), 12L, 
          58L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(94L, 90L, 88L, 0L, -90L, -68L, 94L, -2L, -50L, -92L, 66L, 32L, 10L, 8L, -14L, -96L, 80L, -60L, 48L, -96L, 46L, 24L, 64L, 2L, -30L, 28L), 15L, 
          94L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 17L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(83L, 72L, 91L, 22L, 96L, 38L, 71L, 18L, 58L, 39L, 7L, 8L, 65L, 67L), 7L, 
          -1000000000L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -92L, -88L, -86L, -82L, -80L, -78L, -76L, -74L, -72L, -62L, -54L, -42L, -40L, -38L, -36L, -36L, -34L, -32L, -32L, -26L, -26L, -22L, -14L, -14L, 2L, 16L, 24L, 26L, 32L, 32L, 34L, 48L, 48L, 64L, 66L, 70L, 74L, 82L, 90L), 28L, 
          2L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L), 29L, 
          1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(2L, 2L, 4L, 10L, 11L, 13L, 15L, 20L, 32L, 33L, 33L, 42L, 46L, 46L, 50L, 54L, 55L, 55L, 56L, 57L, 58L, 63L, 68L, 79L, 87L, 94L), 18L, 
          55L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(58L, 78L, 28L, 54L, -10L, 46L, -78L, -68L, -44L, 64L, 78L, 80L, -54L, -38L, -54L, 60L, 26L, 96L), 13L, 
          80L
      )))
  
      cat(sprintf("TEST-8...%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, 1L), 28L, 
          1L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(54L, 55L, 98L, 18L, 11L, 55L, 2L, 95L, 84L, 14L, 75L, 12L, 43L, 54L, 78L, 34L, 69L, 24L, 82L, 65L, 11L, 49L, 34L, 60L, 99L, 71L, 1L, 17L, 88L, 12L, 45L, 46L, 56L, 28L, 70L, 34L, 7L, 55L, 40L, 12L, 38L, 56L, 54L, 53L, 28L), 24L, 
          98L
      )))
  
  }
  
  main()
source_py: def find_largest_d_in_array_such_that_a_b_c_d_1(arr, n):
      mp = dict()
      for i in range((n - 1)):
          for j in range((i + 1), n):
              mp[(arr[i] + arr[j])] = (i, j)
      d = (- (10 ** 9))
      for i in range((n - 1)):
          for j in range((i + 1), n):
              abs_diff = abs((arr[i] - arr[j]))
              if (abs_diff in mp.keys()):
                  p = mp[abs_diff]
                  if ((p[0] != i) and (p[0] != j) and (p[1] != i) and (p[1] != j)):
                      d = max(d, max(arr[i], arr[j]))
      return d
source_cpp: int find_largest_d_in_array_such_that_a_b_c_d_1(vector<int> arr, int n) {
    unordered_map < int, pair < int, int > > mp;
    for ( int i = 0;
    i < n - 1;
    i ++ ) for ( int j = i + 1;
    j < n;
    j ++ ) mp [ arr [ i ] + arr [ j ] ] = {
      i, j };
      int d = INT_MIN;
      for ( int i = 0;
      i < n - 1;
      i ++ ) {
        for ( int j = i + 1;
        j < n;
        j ++ ) {
          int abs_diff = abs ( arr [ i ] - arr [ j ] );
          if ( mp . find ( abs_diff ) != mp . end ( ) ) {
            pair < int, int > p = mp [ abs_diff ];
            if ( p . first != i && p . first != j && p . second != i && p . second != j ) d = max ( d, max ( arr [ i ], arr [ j ] ) );
          }
        }
      }
      return d;
    }