Skip to content
Decoder

Matchsticks to Square

Medium

Problem

You have matchsticks of the lengths in matchsticks. Decide whether you can make a square using every matchstick exactly once. Sticks can be joined end to end but not broken.

Example 1

Input
[1, 1, 2, 2, 2]
Output
True
Why
sides: 2, 2, 2, 1+1

Example 2

Input
[3, 3, 3, 3, 4]
Output
False

Constraints

  • 1 <= matchsticks.length <= 15
  • 1 <= matchsticks[i] <= 10^8

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.