Largest Perimeter Triangle
From LeetCode. Triangle inequality - max perimeter. Solve the geometry problem "Largest Perimeter Triangle".
Examples
Input: [1,2,3]
Output: 0
Input: [2,3,4]
Output: 9
Hints
Sort the side lengths in descending order. The largest perimeter triangle will come from the first triplet that satisfies the triangle inequality.
Iterate through the sorted array and for each triple `(i, i+1, i+2)`, check if `nums[i] < nums[i+1] + nums[i+2]`. Return the sum of the first triple that passes — since you sorted descending, this gives the maximum perimeter.
If no triple passes the check, return 0. The greedy approach works because any non-consecutive triple with a smaller largest side would only yield an equal or smaller perimeter.
Largest Perimeter Triangle
**From LeetCode.** Triangle inequality - max perimeter. Solve the geometry problem "Largest Perimeter Triangle".