title: Find A Triplet That Sum To A Given Value 2
signature: bool findATripletThatSumToAGivenValue2(vector<int> a, int arr_size, int sum) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(bool actual, bool expected){
      return actual == expected;
  }
  
  string driver(vector<int> a, int arr_size, int sum, bool expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(a, arr_size, sum), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      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); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      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); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 13, false); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      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); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      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); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 1, 1, 1, 1, 0, 0}, 5, 3, true); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({8, 8, 9, 13, 20, 24, 29, 52, 53, 96}, 9, 8, false); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      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); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({1, 1, 1, 1}, 2, 2, false); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({72}, 0, 0, false); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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;
  }