codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

ProblemsMatchsticks to Square

Matchsticks to Square

Medium
BacktrackingBit Manipulation

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.

 

Example 1:

Input: matchsticks = [1,1,2,2,2]
Output: true
Explanation: You can form a square with length 2, one side of the square came two sticks of length 1.

Example 2:

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

 

Constraints:

  • 1 <= matchsticks.length <= 15
  • 1 <= matchsticks[i] <= 108

Related Problems

View all
Subsets
Medium•Recursion
Combination Sum
Medium•Recursion
Permutations
Medium•Recursion
Subsets II
Medium•Recursion
Combination Sum II
Medium•Recursion
Word Search
Medium•Recursion
Input:
matchsticks = [1,1,2,2,2]