473. Matchsticks to Square

Practice Matchsticks to Square for free on NudgeCode: Medium, Backtracking pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

matchsticks[i] is the length of one matchstick. Return true if you can form a square using every matchstick exactly once, without breaking any of them. Otherwise return false.

Example

matchsticks = [1,1,2,2,2]  ->  true    (sides 2, 2, 2 and 1+1)
matchsticks = [3,3,3,3,4]  ->  false

Constraints