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 in the array and check if any of the conditions are satisfied.
Use nested lo...read more
Help your peers!
Add answer anonymously...
Jio Platforms Software Engineer interview questions & answers
A Software Engineer was asked Q. What are the features of Java 8?
A Software Engineer was asked Q. What data types are available in Python?
A Software Engineer was asked 10mo agoQ. Past Projects Design
Popular interview questions of Software Engineer
A Software Engineer was asked Q1. What are the features of Java 8?
A Software Engineer was asked Q2. What data types are available in Python?
A Software Engineer was asked Q3. What is encapsulation?
>
Jio Platforms Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

