Sum of Two Elements Equals the Third

Determine if a given array contains a valid triplet of integers where two elements sum up to the third. Specifically, find indices i, j, and k such that i != j, j != k, and i != k, satisfying one of these conditions: arr[i] + arr[j] = arr[k], arr[i] + arr[k] = arr[j], or arr[k] + arr[j] = arr[i].

Input:

The first line of input contains a single integer T, the number of test cases.
Each test case includes: 
- An integer N: The size of the array. 
- A line with N space-separated integers representing the array elements.

Output:

For each test case, output "true" if there is a valid triplet, otherwise output "false".

Example:

Input:
Arr = 10, 5, 5, 6, 2
Output:
true
Explanation:

In this array, the triplet {10, 5, 5} is a valid triplet because 5 + 5 = 10.

Constraints:

  • 1 ≤ T ≤ 50
  • 1 ≤ N ≤ 10^3
  • 1 ≤ Arr[i] ≤ 10^4

Note:

The elements in the array do not need to be distinct.

Be the first one to answer
Add answer anonymously...
Jio Platforms Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter