Matchsticks to Square

Medium

Company Tags

You are given an integer array matchsticks where matchsticks[i] is the length of the ith matchstick. You need to use all the matchsticks to make one square. You should not break any stick, but you can link them up, and each matchstick must be used exactly one time.

Return true if you can make this square and false otherwise.

Example 1:

Input: matchsticks = [1,3,4,2,2,4]

Output: true

Example 2:

Input: matchsticks = [1,5,6,3]

Output: false

Constraints:

  • 1 <= matchsticks.length <= 15.
  • 1 <= matchsticks[i] <= 100,000,000


Company Tags

Please upgrade to NeetCode Pro to view company tags.

matchsticks =