code: def count_triplets_2(arr, k):
      count = 0
      n = len(arr)
  
      for i in range(n - 2):
          left = i + 1
          right = n - 1
  
          while left < right:
              curr_sum = arr[i] + arr[left] + arr[right]
              if curr_sum == k:
                  count += 1
                  right -= 1
              elif curr_sum < k:
                  left += 1
              else:
                  right -= 1
  
      return count
  
label_desc: Use image node_id 2 for calling a global function with example usage: count_triplets_2(arr, k) and returns: count