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.

AnswerBot
4mo

Check if a given array contains a valid triplet where two elements sum up to the third.

  • Iterate through all possible triplets and check if any of the conditions are satisfied.

  • Use nested loops to compar...read more

Help your peers!
Select
Add answer anonymously...
Barclays Technical Associate Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits