Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Sum of Two Elements Equals the Third.
EASY
10 mins
14 upvotes
Sorting
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Sorting
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Sum of Two Elements Equals the Third.

Contributed by
Nishant Chitkara
Easy
yellow-spark
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share
14 upvotes

Problem Statement

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.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
4
1 1 1 1
5
10 5 5 6 2
Sample Output 1:
false
true
Explanation For Sample Input 1:
In the first case, no valid triplet can be formed.

5 5 10 is the triplet in which the sum of two elements {5,5} is equal to the third {10}.
Sample Input 2:
2
6
1 2 3 1 2 3
6
1 1 2 2 1 1
Sample Output 2:
 true
 true
Reset Code
Full screen
Auto
copy-code
Console