Ctrl K

Square Frame From Sticks

Medium
You have a set of sticks, and 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.
Example 1
sticks=[3, 1, 2, 2, 1, 3] → True

The total is 12, so each side is 3: 3, 3, 1 + 2 and 2 + 1.

Example 2
sticks=[4, 4, 4, 2, 2] → True

The total is 16, so each side is 4: 4, 4, 4 and 2 + 2.

Example 3
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.

Constraints
  • 1 ≤ len(sticks) ≤ 15
  • 1 ≤ sticks[i] ≤ 10⁸
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSeating by Divisibility MediumCheapest Basket with Bundles MediumGroups With Equal Sums MediumLeast Total Walk to Scooters MediumTrainees and Coaches Medium
loading Python…
Input
sticks=[3, 1, 2, 2, 1, 3]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.