#K74602. Triplet Sum to Target

    ID: 34234 Type: Default 1000ms 256MiB

Triplet Sum to Target

Triplet Sum to Target

Given an array of n integers and a target integer \(T\), determine if there exists a triplet of numbers in the array whose sum equals \(T\). The triplet must consist of three distinct elements from the array.

Efficient solutions are required for larger inputs. This problem tests your ability to implement a two-pointer technique after sorting the array.

inputFormat

The input is given via stdin in the following format:

  • The first line contains an integer \(n\), representing the number of elements in the array.
  • The second line contains \(n\) space-separated integers.
  • The third line contains an integer \(T\), the target sum.

outputFormat

Output via stdout a single line containing True if there exists a triplet in the array whose sum equals \(T\), or False otherwise.

## sample
6
12 3 4 1 6 9
24
True