sticks. In how many ways can you pick three sticks (three different positions of the array) that can be put together into a triangle?
Three lengths form a triangle when the sum of any two of them is strictly greater than the third. Sticks of equal length at different positions are different sticks, so triples with the same lengths may be counted more than once.sticks=[3, 5, 5, 9] → 2
(3, 5, 5) and (5, 5, 9) work. Neither (3, 5, 9) triple does, one with each 5, because 3 + 5 < 9.
sticks=[2, 2, 2, 2] → 4
Any three sticks form an equilateral triangle, and there are 4 ways to pick three of four.
sticks=[1, 2, 3] → 0
1 + 2 = 3 gives a flat triangle, which does not count.
sticks=[3, 5, 5, 9]
2
Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.