title: Find Largest D In Array Such That A B C D 1
signature: function find_largest_d_in_array_such_that_a_b_c_d_1(arr, n)
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;
    }
question_info.entry_fn_name: find_largest_d_in_array_such_that_a_b_c_d_1
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({1, 1, 5, 7, 10, 35, 35, 45, 49, 50, 57, 58, 60, 64, 69, 83, 83, 87, 88, 89, 93, 94}, 12, 58)
      print(string.format("TEST-0...%s",result))
  
      result = driver({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)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({83, 72, 91, 22, 96, 38, 71, 18, 58, 39, 7, 8, 65, 67}, 7, -1000000000)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-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)
      print(string.format("TEST-4...%s",result))
  
      result = driver({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)
      print(string.format("TEST-5...%s",result))
  
      result = driver({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)
      print(string.format("TEST-6...%s",result))
  
      result = driver({58, 78, 28, 54, -10, 46, -78, -68, -44, 64, 78, 80, -54, -38, -54, 60, 26, 96}, 13, 80)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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)
      print(string.format("TEST-8...%s",result))
  
      result = driver({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)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 58, "inputs": {"arr": [1, 1, 5, 7, 10, 35, 35, 45, 49, 50, 57, 58, 60, 64, 69, 83, 83, 87, 88, 89, 93, 94], "n": 12}}, {"idx": 1, "outputs": 94, "inputs": {"arr": [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], "n": 15}}, {"idx": 2, "outputs": 1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 17}}, {"idx": 3, "outputs": -1000000000, "inputs": {"arr": [83, 72, 91, 22, 96, 38, 71, 18, 58, 39, 7, 8, 65, 67], "n": 7}}, {"idx": 4, "outputs": 2, "inputs": {"arr": [-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], "n": 28}}, {"idx": 5, "outputs": 1, "inputs": {"arr": [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], "n": 29}}, {"idx": 6, "outputs": 55, "inputs": {"arr": [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], "n": 18}}, {"idx": 7, "outputs": 80, "inputs": {"arr": [58, 78, 28, 54, -10, 46, -78, -68, -44, 64, 78, 80, -54, -38, -54, 60, 26, 96], "n": 13}}, {"idx": 8, "outputs": 1, "inputs": {"arr": [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], "n": 28}}, {"idx": 9, "outputs": 98, "inputs": {"arr": [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], "n": 24}}]