title: Find A Triplet That Sum To A Given Value 2
signature: function find_a_triplet_that_sum_to_a_given_value_2(a, arr_size, sum)
source_py: def find_a_triplet_that_sum_to_a_given_value_2(A, arr_size, sum):
      for i in range(0, (arr_size - 1)):
          s = set()
          curr_sum = (sum - A[i])
          for j in range((i + 1), arr_size):
              if ((curr_sum - A[j]) in s):
                  print('Triplet is', A[i], ', ', A[j], ', ', (curr_sum - A[j]))
                  return True
              s.add(A[j])
      return False
source_cpp: bool find_a_triplet_that_sum_to_a_given_value_2(vector<int> A, int arr_size, int sum) {
    for ( int i = 0;
    i < arr_size - 2;
    i ++ ) {
      unordered_set < int > s;
      int curr_sum = sum - A [ i ];
      for ( int j = i + 1;
      j < arr_size;
      j ++ ) {
        if ( s . find ( curr_sum - A [ j ] ) != s . end ( ) ) {
          return true;
        }
        s . insert ( A [ j ] );
      }
    }
    return false;
  }
question_info.entry_fn_name: find_a_triplet_that_sum_to_a_given_value_2
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(a, arr_size, sum, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(a, arr_size, sum) 
      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, 6, 8, 8, 9, 11, 13, 13, 15, 17, 21, 24, 38, 38, 42, 43, 46, 46, 47, 54, 55, 56, 57, 58, 60, 60, 60, 62, 63, 63, 65, 66, 67, 67, 69, 81, 84, 84, 85, 86, 95, 99}, 27, 24, true)
      print(string.format("TEST-0...%s",result))
  
      result = driver({20, -86, -24, 38, -32, -64, -72, 72, 68, 94, 18, -60, -4, -18, -18, -70, 6, -86, 46, -16, 46, -28}, 21, 20, true)
      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}, 17, 13, false)
      print(string.format("TEST-2...%s",result))
  
      result = driver({13, 96, 31, 39, 23, 39, 50, 10, 21, 64, 41, 54, 44, 97, 24, 91, 79, 86, 38, 49, 77, 71, 8, 98, 85, 36, 37, 65, 42, 48}, 17, 18, false)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-86, -68, -58, -56, -54, -54, -48, -40, -36, -32, -26, -16, -14, -12, -12, -4, -4, -4, 0, 10, 22, 22, 30, 54, 62, 68, 88, 88}, 21, 25, false)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 1, 1, 1, 1, 0, 0}, 5, 3, true)
      print(string.format("TEST-5...%s",result))
  
      result = driver({8, 8, 9, 13, 20, 24, 29, 52, 53, 96}, 9, 8, false)
      print(string.format("TEST-6...%s",result))
  
      result = driver({18, -92, -10, 26, 58, -48, 38, 66, -98, -72, 4, 76, -52, 20, 60, -56, 96, 60, -10, -26, -64, -66, -22, -86, 74, 82, 2, -14, 76, 82, 40, 70, -40, -2, -46, -38, 22, 98, 58}, 30, 30, true)
      print(string.format("TEST-7...%s",result))
  
      result = driver({1, 1, 1, 1}, 2, 2, false)
      print(string.format("TEST-8...%s",result))
  
      result = driver({72}, 0, 0, false)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": true, "inputs": {"a": [1, 6, 8, 8, 9, 11, 13, 13, 15, 17, 21, 24, 38, 38, 42, 43, 46, 46, 47, 54, 55, 56, 57, 58, 60, 60, 60, 62, 63, 63, 65, 66, 67, 67, 69, 81, 84, 84, 85, 86, 95, 99], "arr_size": 27, "sum": 24}}, {"idx": 1, "outputs": true, "inputs": {"a": [20, -86, -24, 38, -32, -64, -72, 72, 68, 94, 18, -60, -4, -18, -18, -70, 6, -86, 46, -16, 46, -28], "arr_size": 21, "sum": 20}}, {"idx": 2, "outputs": false, "inputs": {"a": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], "arr_size": 17, "sum": 13}}, {"idx": 3, "outputs": false, "inputs": {"a": [13, 96, 31, 39, 23, 39, 50, 10, 21, 64, 41, 54, 44, 97, 24, 91, 79, 86, 38, 49, 77, 71, 8, 98, 85, 36, 37, 65, 42, 48], "arr_size": 17, "sum": 18}}, {"idx": 4, "outputs": false, "inputs": {"a": [-86, -68, -58, -56, -54, -54, -48, -40, -36, -32, -26, -16, -14, -12, -12, -4, -4, -4, 0, 10, 22, 22, 30, 54, 62, 68, 88, 88], "arr_size": 21, "sum": 25}}, {"idx": 5, "outputs": true, "inputs": {"a": [0, 1, 1, 1, 1, 0, 0], "arr_size": 5, "sum": 3}}, {"idx": 6, "outputs": false, "inputs": {"a": [8, 8, 9, 13, 20, 24, 29, 52, 53, 96], "arr_size": 9, "sum": 8}}, {"idx": 7, "outputs": true, "inputs": {"a": [18, -92, -10, 26, 58, -48, 38, 66, -98, -72, 4, 76, -52, 20, 60, -56, 96, 60, -10, -26, -64, -66, -22, -86, 74, 82, 2, -14, 76, 82, 40, 70, -40, -2, -46, -38, 22, 98, 58], "arr_size": 30, "sum": 30}}, {"idx": 8, "outputs": false, "inputs": {"a": [1, 1, 1, 1], "arr_size": 2, "sum": 2}}, {"idx": 9, "outputs": false, "inputs": {"a": [72], "arr_size": 0, "sum": 0}}]