sticks. Pick some of them to form a polygon: it needs at least 3 sides, and its longest side must be strictly shorter than the sum of all the other sides. Whenever that holds, a polygon with those sides always exists.
Each stick can be used at most once. Return the largest possible perimeter (the sum of the side lengths) of such a polygon, or -1 if no polygon can be formed.sticks=[2, 3, 4, 20] → 9
The 20 stick is longer than all the others combined (9), so it cannot be used. 2, 3 and 4 make a triangle since 4 < 2 + 3, giving a perimeter of 9.
sticks=[1, 2, 3] → -1
3 is not less than 1 + 2, so the shape collapses into a line and no polygon can be built.
sticks=[6, 1, 1, 2, 3, 4] → 17
sticks=[2, 3, 4, 20]
9
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.