title: Find A Triplet That Sum To A Given Value 2
signature: func findATripletThatSumToAGivenValue2(a []int, arr_size int, sum int) bool {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual bool, expected bool) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(a []int, arr_size int, sum int, expected bool) string {
      if validateSolution(PLACEHOLDER_FN_NAME(a, arr_size, sum),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver([]int{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)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver([]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
  	17, 
  	13, false)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver([]int{-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)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver([]int{0, 1, 1, 1, 1, 0, 0}, 
  	5, 
  	3, true)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver([]int{8, 8, 9, 13, 20, 24, 29, 52, 53, 96}, 
  	9, 
  	8, false)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver([]int{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)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver([]int{1, 1, 1, 1}, 
  	2, 
  	2, false)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver([]int{72}, 
  	0, 
  	0, false)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }