Sum of Two Elements Equals the Third.
You are given an array Arr consisting of n integers, you need to find a valid triplet as explained below.
An array is said to have a valid triplet {arr[i], arr[j], arr[k]} if there exists three indices i, j and k such that i != j, j != k and i != j and arr[i] + arr[j] = arr[k] or arr[i] + arr[k] = arr[j] or arr[k] + arr[j] = arr[i].
For Example:
Arr = 10, 5, 5, 6, 2,
In this array, the triplet {10, 5, 5} is valid triplet because, 5 + 5 = 10.
Note:
The elements in the array need not be distinct.
Input Format:
The first line of the input contains an integer T, denoting the number of test cases.
The first line of each test case contains the integer N, denoting the size of the array.
The second line of each test case contains N space-separated integers denoting the array elements.
Output Format:
For each test case, every line of output contains “true” if there is a valid triplet and the user has returned a valid one, else "false" will be printed.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 50
1 <= N <= 10^3
1 <= Arr[i] <= 10^4
Time Limit: 1 sec
Be the first one to answer
Add answer anonymously...
Top Barclays Technical Associate interview questions & answers
Popular interview questions of Technical Associate
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app