sticks[i] is the length of the i-th one. You want to lay out the outline of a square: every stick must be used exactly once, sticks cannot be broken, but several sticks may be placed end to end along one side.
Return True if the square can be made and False otherwise.sticks=[3, 1, 2, 2, 1, 3] → True
The total is 12, so each side is 3: 3, 3, 1 + 2 and 2 + 1.
sticks=[4, 4, 4, 2, 2] → True
The total is 16, so each side is 4: 4, 4, 4 and 2 + 2.
sticks=[5, 5, 5, 3, 2, 4] → False
The total is 24, so each side is 6, yet each 5 would need a 1 to reach 6, and there are no 1s.
sticks=[3, 1, 2, 2, 1, 3]
True
Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.