Close
Topic list
Sum of Two Elements Equals the Third.
EASY
10 mins
Sorting
Topics (Covered in this problem)
Problem solved
Skill meter
Sorting
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
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
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
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share

## Problem Statement

#### 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
``````
Auto
Console