title: Find A Triplet That Sum To A Given Value 1
signature: find_a_triplet_that_sum_to_a_given_value_1 <- 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(28L, 47L, 65L, 89L), 3L, 3L, 
          FALSE
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-90L, -88L, -88L, -70L, -66L, -64L, -64L, -56L, -52L, -48L, -42L, -40L, -26L, -16L, -14L, -8L, -2L, 0L, 6L, 12L, 12L, 14L, 18L, 46L, 50L, 52L, 52L, 52L, 58L, 68L, 70L, 70L, 74L, 78L, 84L, 96L, 98L), 22L, 24L, 
          TRUE
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L), 0L, 0L, 
          FALSE
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(22L, 49L, 52L, 54L, 66L, 80L, 87L, 93L), 5L, 7L, 
          FALSE
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-96L, -92L, -86L, -74L, -62L, -60L, -56L, -54L, -46L, -38L, -32L, -26L, -16L, -16L, -8L, -4L, 0L, 6L, 20L, 28L, 42L, 44L, 56L), 13L, 19L, 
          FALSE
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 39L, 39L, 
          FALSE
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(1L, 2L, 16L, 16L, 20L, 24L, 24L, 38L, 41L, 54L, 57L, 72L, 79L, 83L, 89L, 90L, 96L, 97L, 98L), 12L, 12L, 
          FALSE
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-30L, 22L, 52L, 78L), 2L, 3L, 
          FALSE
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 21L, 16L, 
          FALSE
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(1L, 4L, 6L, 9L, 10L, 11L, 11L, 16L, 16L, 20L, 23L, 26L, 28L, 28L, 40L, 41L, 41L, 44L, 48L, 49L, 50L, 51L, 52L, 58L, 58L, 72L, 77L, 83L, 83L, 92L, 92L, 98L), 29L, 27L, 
          TRUE
      )))
  
  }
  
  main()
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;
  }