
Asked in Barclays
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!
Add answer anonymously...
Interview Questions Asked to Technical Associate at Other Companies
Top Skill-Based Questions for Barclays Technical Associate
Java Interview Questions and Answers
250 Questions
Networking Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 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

