title: Find A Triplet That Sum To A Given Value 1
signature: function find_a_triplet_that_sum_to_a_given_value_1(a, arr_size, sum)
source_py: def find_a_triplet_that_sum_to_a_given_value_1(A, arr_size, sum):
      A.sort()
      for i in range(0, (arr_size - 2)):
          l = (i + 1)
          r = (arr_size - 1)
          while (l < r):
              if (((A[i] + A[l]) + A[r]) == sum):
                  print('Triplet is', A[i], ', ', A[l], ', ', A[r])
                  return True
              elif (((A[i] + A[l]) + A[r]) < sum):
                  l += 1
              else:
                  r -= 1
      return False
source_cpp: bool find_a_triplet_that_sum_to_a_given_value_1(vector<int> A, int arr_size, int sum) {
    int l, r;
    sort(A.begin(), A.end());
    for ( int i = 0;
    i < arr_size - 2;
    i ++ ) {
      l = i + 1;
      r = arr_size - 1;
      while ( l < r ) {
        if ( A [ i ] + A [ l ] + A [ r ] == sum ) {
          return true;
        }
        else if ( A [ i ] + A [ l ] + A [ r ] < sum ) l ++;
        else r --;
      }
    }
    return false;
  }
question_info.entry_fn_name: find_a_triplet_that_sum_to_a_given_value_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(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({28, 47, 65, 89}, 3, 3, false)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-90, -88, -88, -70, -66, -64, -64, -56, -52, -48, -42, -40, -26, -16, -14, -8, -2, 0, 6, 12, 12, 14, 18, 46, 50, 52, 52, 52, 58, 68, 70, 70, 74, 78, 84, 96, 98}, 22, 24, true)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0}, 0, 0, false)
      print(string.format("TEST-2...%s",result))
  
      result = driver({22, 49, 52, 54, 66, 80, 87, 93}, 5, 7, false)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-96, -92, -86, -74, -62, -60, -56, -54, -46, -38, -32, -26, -16, -16, -8, -4, 0, 6, 20, 28, 42, 44, 56}, 13, 19, false)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1}, 39, 39, false)
      print(string.format("TEST-5...%s",result))
  
      result = driver({1, 2, 16, 16, 20, 24, 24, 38, 41, 54, 57, 72, 79, 83, 89, 90, 96, 97, 98}, 12, 12, false)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-30, 22, 52, 78}, 2, 3, false)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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}, 21, 16, false)
      print(string.format("TEST-8...%s",result))
  
      result = driver({1, 4, 6, 9, 10, 11, 11, 16, 16, 20, 23, 26, 28, 28, 40, 41, 41, 44, 48, 49, 50, 51, 52, 58, 58, 72, 77, 83, 83, 92, 92, 98}, 29, 27, true)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": false, "inputs": {"a": [28, 47, 65, 89], "arr_size": 3, "sum": 3}}, {"idx": 1, "outputs": true, "inputs": {"a": [-90, -88, -88, -70, -66, -64, -64, -56, -52, -48, -42, -40, -26, -16, -14, -8, -2, 0, 6, 12, 12, 14, 18, 46, 50, 52, 52, 52, 58, 68, 70, 70, 74, 78, 84, 96, 98], "arr_size": 22, "sum": 24}}, {"idx": 2, "outputs": false, "inputs": {"a": [0], "arr_size": 0, "sum": 0}}, {"idx": 3, "outputs": false, "inputs": {"a": [22, 49, 52, 54, 66, 80, 87, 93], "arr_size": 5, "sum": 7}}, {"idx": 4, "outputs": false, "inputs": {"a": [-96, -92, -86, -74, -62, -60, -56, -54, -46, -38, -32, -26, -16, -16, -8, -4, 0, 6, 20, 28, 42, 44, 56], "arr_size": 13, "sum": 19}}, {"idx": 5, "outputs": false, "inputs": {"a": [0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1], "arr_size": 39, "sum": 39}}, {"idx": 6, "outputs": false, "inputs": {"a": [1, 2, 16, 16, 20, 24, 24, 38, 41, 54, 57, 72, 79, 83, 89, 90, 96, 97, 98], "arr_size": 12, "sum": 12}}, {"idx": 7, "outputs": false, "inputs": {"a": [-30, 22, 52, 78], "arr_size": 2, "sum": 3}}, {"idx": 8, "outputs": false, "inputs": {"a": [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], "arr_size": 21, "sum": 16}}, {"idx": 9, "outputs": true, "inputs": {"a": [1, 4, 6, 9, 10, 11, 11, 16, 16, 20, 23, 26, 28, 28, 40, 41, 41, 44, 48, 49, 50, 51, 52, 58, 58, 72, 77, 83, 83, 92, 92, 98], "arr_size": 29, "sum": 27}}]