title: Find Largest D In Array Such That A B C D 1
signature: func findLargestDInArraySuchThatABCD1(arr []int, n int) int64 {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int64, expected int64) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(arr []int, n int, expected int64) string {
      if validateSolution(PLACEHOLDER_FN_NAME(arr, n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{1, 1, 5, 7, 10, 35, 35, 45, 49, 50, 57, 58, 60, 64, 69, 83, 83, 87, 88, 89, 93, 94}, 
  	12, 58)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{94, 90, 88, 0, -90, -68, 94, -2, -50, -92, 66, 32, 10, 8, -14, -96, 80, -60, 48, -96, 46, 24, 64, 2, -30, 28}, 
  	15, 94)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	17, 1)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{83, 72, 91, 22, 96, 38, 71, 18, 58, 39, 7, 8, 65, 67}, 
  	7, -1000000000)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-96, -92, -88, -86, -82, -80, -78, -76, -74, -72, -62, -54, -42, -40, -38, -36, -36, -34, -32, -32, -26, -26, -22, -14, -14, 2, 16, 24, 26, 32, 32, 34, 48, 48, 64, 66, 70, 74, 82, 90}, 
  	28, 2)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1}, 
  	29, 1)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{2, 2, 4, 10, 11, 13, 15, 20, 32, 33, 33, 42, 46, 46, 50, 54, 55, 55, 56, 57, 58, 63, 68, 79, 87, 94}, 
  	18, 55)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{58, 78, 28, 54, -10, 46, -78, -68, -44, 64, 78, 80, -54, -38, -54, 60, 26, 96}, 
  	13, 80)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{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}, 
  	28, 1)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{54, 55, 98, 18, 11, 55, 2, 95, 84, 14, 75, 12, 43, 54, 78, 34, 69, 24, 82, 65, 11, 49, 34, 60, 99, 71, 1, 17, 88, 12, 45, 46, 56, 28, 70, 34, 7, 55, 40, 12, 38, 56, 54, 53, 28}, 
  	24, 98)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
    }