Triangle Existence Checker
Given an array of three integer numbers representing the lengths of the sides of a triangle, determine whether these sides can form a valid triangle. A set of three sides can form a triangle if the sum of the lengths of any two sides is greater than the length of the third side. The function must return 'Yes' if the sides can form a triangle and 'No' otherwise.
[ 3, 4, 5 ]
Explanation. 3 + 4 > 5, 4 + 5 > 3, and 3 + 5 > 4.
[ 1, 2, 3 ]
Explanation. 1 + 2 is not greater than 3.
[ 5, 5, 5 ]
Explanation. All side combinations sum to more than the third side.
[ 10, 1, 2 ]
Explanation. 10 is greater than 1 + 2, cannot form a triangle.
[ 7, 6, 10 ]
Explanation. All side combinations sum to more than the third side.
Follow-up: How would your solution change if you also had to determine the type of triangle (equilateral, isosceles, or scalene)?
All side lengths are positive integers.
- Views
- 3