title: Find A Triplet That Sum To A Given Value 2
signature: class Solution {
  
      public Boolean findATripletThatSumToAGivenValue2(ArrayList<Integer> a, Integer arr_size, Integer sum) {
test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> a, Integer arr_size, Integer sum, Boolean expected){
          try{
              Driver driver = new Driver();
              if (driver.run(a, arr_size, sum,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 17, 13, false);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-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);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 1, 1, 1, 1, 0, 0)), 5, 3, true);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(8, 8, 9, 13, 20, 24, 29, 52, 53, 96)), 9, 8, false);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 1, 1, 1)), 2, 2, false);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(72)), 0, 0, false);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> a, Integer arr_size, Integer sum, Boolean expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(a, arr_size, sum),expected);
      }
      
      public boolean validateSolution(Boolean actual, Boolean expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
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;
  }