You are given an integer array nums, where each value represents the length of a side.
Your task is to return the largest possible perimeter of a triangle that has non-zero area and can be formed using any three lengths from the array.
A triangle is valid if it satisfies the triangle inequality:
(where c is the largest side)
If no valid triangle can be formed, return 0.
Input: nums = [2, 1, 2]
Output: 5
Explanation:
A triangle can be formed with sides 1, 2, and 2, and the perimeter is 5.
Input: nums = [1, 2, 1, 10]
Output: 0
Explanation:
No three lengths satisfy the triangle inequality. So no triangle with non-zero area can be formed.
Accepted:
Submission: