Skip to content

Practice Matchsticks to Square

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#473
LeetCode Problem

Matchsticks to Square

Problem Statement

You are given an integer array matchsticks where matchsticks[i] is the length of the ith matchstick. You want 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.

Source: Matchsticks to Square on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
matchsticks = [1,1,2,2,2]
Output
true

# Example 2

Input
matchsticks = [3,3,3,3,4]
Output
false

Constraints

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

Related LeetCode Problems

Practice more problems similar to Matchsticks to Square.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.