#K67187. Three Sum Existence Problem
Three Sum Existence Problem
Three Sum Existence Problem
You are given an array of integers and a target integer \(k\). Your task is to determine whether there exist three distinct elements in the array whose sum is equal to \(k\). If such a triplet exists, print True
; otherwise, print False
.
Note: The three numbers must come from different positions in the array. The input is provided via standard input (stdin) and the output should be printed to standard output (stdout). Efficient solutions are preferred.
For example:
Input: 6 1 2 3 4 5 6 10</p>Output: True
Explanation: One possible triplet is 1, 3, and 6 (\(1 + 3 + 6 = 10\)).
inputFormat
The first line of input contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers indicating the array elements. The third line contains the target integer \(k\).
Example:
6 1 2 3 4 5 6 10
outputFormat
Output a single line with True
if there exists any triplet of distinct elements whose sum equals \(k\); otherwise, output False
.
6
1 2 3 4 5 6
10
True