Matchsticks to Square
A medium-tier problem at 41% community acceptance, tagged with Array, Dynamic Programming, Backtracking. Reported in interviews at PhonePe and 1 others.
Matchsticks to Square is a medium-difficulty problem that appears in assessments at PhonePe and eBay. You're given an array of matchstick lengths and need to determine if you can arrange them into four equal-length sides of a square. The 41% acceptance rate signals a trap: the greedy approach fails, and most candidates who don't spot the pattern burn time on dead-end implementations. This is exactly the kind of problem where you hit a wall three minutes in, and StealthCoder runs invisibly during your assessment to surface a working solution before the timer kills you.
Companies that ask "Matchsticks to Square"
Matchsticks to Square is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe trick is recognizing that each matchstick must be assigned to one of four sides, and all sides must sum to the same target length. You can't just check if the total is divisible by four. The actual work is a backtracking search through stick assignments, often paired with bitmask optimization to prune the search space early. Most candidates default to recursive DFS with memoization, which works, but without careful pruning (sorting sticks descending, cutting branches where a stick exceeds the target) the solution times out. The problem forces you to think about state representation and cutoff heuristics. If you haven't drilled backtracking with bitmask, you'll struggle to recognize the pattern on the fly. StealthCoder handles both the brute-force backtrack and optimized bitmask variant, so even if the DP angle doesn't click during your live OA, you get a working submission in seconds.
Pattern tags
You know the problem.
Make sure you actually pass it.
Matchsticks to Square recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Matchsticks to Square interview FAQ
Is Matchsticks to Square still asked at big companies?+
Yes. PhonePe and eBay both report it. At 41% acceptance, it's not a gimme, but it's standard enough that you'll see it in real assessments. It's not the hardest DP problem, but it punishes candidates who skip backtracking practice.
What's the trick that most people miss?+
Assuming divisibility by four is enough. The actual constraint is assignment: each stick goes to exactly one side, and all four sides must be equal. That forces a search problem, not a math problem. Greedy or simple sorting won't cut it.
Does bitmask DP actually matter for this problem?+
Not always. Backtracking with smart pruning (sort descending, fail fast) beats bitmask for most inputs. Bitmask shines if you cache states aggressively, but it's overkill unless the input is small and fully random. Know both, use what fits.
How does this relate to the other backtracking topics?+
It's classic backtracking with an optimization layer. Unlike N-Queens or Permutations, here you're optimizing a numeric constraint (equal sums) rather than just finding a valid assignment. That's why DFS alone fails and pruning becomes critical.
Can I solve this in under 15 minutes cold?+
Not reliably if you've never seen the pattern. The 41% acceptance suggests most people take longer or don't finish. If backtracking isn't second nature, expect to get stuck on implementation or timeouts. That's when StealthCoder closes the gap.
Want the actual problem statement? View "Matchsticks to Square" on LeetCode →