Mahmoud and a Triangle
From Codeforces. Triangle inequality on sorted array. Solve the geometry problem "Mahmoud and a Triangle".
Examples
Input: [1,2,3]
Output: 0
Input: [2,3,4]
Output: 0
Hints
Sort the stick lengths. For any three sticks to form a non-degenerate triangle, the sum of the two shorter ones must be strictly greater than the longest one.
Because the array is sorted, the most promising triple to try is consecutive elements: `nums[i] + nums[i+1] > nums[i+2]`. If any consecutive triple passes, the answer is YES. This works because consecutive sticks are closest in length, maximizing the chance of satisfying the inequality.
If no consecutive triple forms a triangle, no non-consecutive triple will either — you can immediately return NO. This greedy property holds because for `a ≤ b ≤ c ≤ d`, if `a + b ≤ c` then `a + b ≤ d` as well.
Mahmoud and a Triangle
**From Codeforces.** Triangle inequality on sorted array. Solve the geometry problem "Mahmoud and a Triangle".