A golden triangle has the length of all sides that always less than the sum of the remaining sides.
For example,
-
a triangle with side lengths 10, 5, 8.
The following triangle is a golden triangle because
10 + 5 > 8
5 + 8 > 10
8 + 10 > 5 -
a triangle with side lengths 3, 4, 5.
The following triangle is a golden triangle because
3 + 4 > 5
4 + 5 > 3
5 + 3 > 4 -
a triangle with side lengths 3, 4, 20.
The following triangle is not a golden triangle because
3 + 4 < 20 *This doesn’t match the condition
20 + 3 > 4
4 + 20 > 3
Let T be an array of integers of size N.
N is a positive integer with values >= 0 and <= 100,000.
The values in Array T are in range from −2,147,483,648 to 2,147,483,647.
Example 1
T = [10,2,5,1,8,20]
the function will return true.
due to
T[0]=10, T[2]=(5), T[4]=(8)
can create a golden triangle as explianed in the example above
Example 2
T = [10,50,5,1]
the function will return false
Since there are no values in the array that can create a golden triangle.
Submission:
Write a function to find a golden triangle from aray T (return true or false)
Note:
The time limit is 1 hour, and if the candidate uses more than one for loop, the candidate will lose some scores ( expected program efficiency O(n) )