Update appNew update is available. Click here to update.

Form a Triangle

Contributed by
Ankush Gupta
Easy
yellow-spark
0/40
15 mins
80 %
69 upvotes

Problem Statement

You are given an integer of array/list 'ARR' of length ‘N. You are supposed to return true if it is possible to construct at least one non-degenerate triangle using values of array/list as sides of the triangle, otherwise, return false.

Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= T <= 100
3 <= N <= 10 ^ 3
0 <= ARR[i] <= 10 ^ 9

Where ‘T’ denotes the number of test cases, ‘N’ denotes the number of elements in the array, and 'ARR[i] denotes the elements of the array.

Time Limit: 1 sec.
Sample Input 1 :
2
5
4 2 1 3 2
5
5 2 7 3 15
Sample Output 1:
YES
YES
Explanation of Sample Input 1:
In the first test case, if we choose the sides as { 2,3,4} or {2,2,1} or {2,2,3} then it is possible to form a non-degenerate triangle.

In the second test case, if we choose sides as {5,3,7}, then it is possible to form a non-degenerate triangle.
Sample Input 2:
2
5
12 3 7 4 28
4
7 12 9 20
Sample Output 2:
NO
YES
Explanation of Sample Input 2:
In the first test case, there is no possible way to choose three elements such that they will form the sides of a triangle.

In the second test case, if we choose the sides as {7,12,9} or {12,9,20}, then it is possible to form a non-degenerate triangle
Full screen
Reset Code
Full screen
Autocomplete
copy-code
Console