#K93107. Four Sum Problem
Four Sum Problem
Four Sum Problem
You are given an array of integers and a target integer \(T\). Your task is to determine whether there exist any four distinct numbers in the array whose sum equals \(T\). More formally, given an array \(A = [a_1, a_2, \dots, a_n]\) and an integer \(T\), check if there exist indices \(i, j, k, l\) (all distinct) such that:
\(a_i + a_j + a_k + a_l = T\)
If such a quadruplet exists, output True
; otherwise, output False
.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- The first line contains a single integer \(n\) which is the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the elements of the array. If \(n = 0\), this line may be empty.
- The third line contains a single integer \(T\), the target sum.
outputFormat
Output a single line to standard output (stdout) containing either True
if there exists any quadruplet of numbers in the array that sums to \(T\), or False
otherwise.
6
1 0 -1 0 -2 2
0
True