title: Find A Triplet That Sum To A Given Value 2
signature: find_a_triplet_that_sum_to_a_given_value_2 <- function(a, arr_size, sum) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, arr_size, sum, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, arr_size, sum), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(1L, 6L, 8L, 8L, 9L, 11L, 13L, 13L, 15L, 17L, 21L, 24L, 38L, 38L, 42L, 43L, 46L, 46L, 47L, 54L, 55L, 56L, 57L, 58L, 60L, 60L, 60L, 62L, 63L, 63L, 65L, 66L, 67L, 67L, 69L, 81L, 84L, 84L, 85L, 86L, 95L, 99L), 27L, 24L, 
          TRUE
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(20L, -86L, -24L, 38L, -32L, -64L, -72L, 72L, 68L, 94L, 18L, -60L, -4L, -18L, -18L, -70L, 6L, -86L, 46L, -16L, 46L, -28L), 21L, 20L, 
          TRUE
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 17L, 13L, 
          FALSE
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(13L, 96L, 31L, 39L, 23L, 39L, 50L, 10L, 21L, 64L, 41L, 54L, 44L, 97L, 24L, 91L, 79L, 86L, 38L, 49L, 77L, 71L, 8L, 98L, 85L, 36L, 37L, 65L, 42L, 48L), 17L, 18L, 
          FALSE
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-86L, -68L, -58L, -56L, -54L, -54L, -48L, -40L, -36L, -32L, -26L, -16L, -14L, -12L, -12L, -4L, -4L, -4L, 0L, 10L, 22L, 22L, 30L, 54L, 62L, 68L, 88L, 88L), 21L, 25L, 
          FALSE
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 1L, 1L, 1L, 0L, 0L), 5L, 3L, 
          TRUE
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(8L, 8L, 9L, 13L, 20L, 24L, 29L, 52L, 53L, 96L), 9L, 8L, 
          FALSE
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(18L, -92L, -10L, 26L, 58L, -48L, 38L, 66L, -98L, -72L, 4L, 76L, -52L, 20L, 60L, -56L, 96L, 60L, -10L, -26L, -64L, -66L, -22L, -86L, 74L, 82L, 2L, -14L, 76L, 82L, 40L, 70L, -40L, -2L, -46L, -38L, 22L, 98L, 58L), 30L, 30L, 
          TRUE
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(1L, 1L, 1L, 1L), 2L, 2L, 
          FALSE
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(72L), 0L, 0L, 
          FALSE
      )))
  
  }
  
  main()
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;
  }