sticks. Pick exactly three of them to build a triangle with non-zero area, making its perimeter as large as possible.
Three lengths form a real triangle only when the two shorter ones add up to strictly more than the longest.
Return the largest perimeter you can get. If no three sticks work, return 0.sticks=[4, 9, 6, 3] → 19
9, 6 and 4 make a triangle (6 + 4 > 9) with perimeter 19, the largest possible.
sticks=[2, 3, 5, 12] → 0
No triple works: for instance 2 + 3 = 5, so that "triangle" collapses into a segment. The answer is 0.
sticks=[7, 7, 7] → 21
sticks=[4, 9, 6, 3]
19
Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.