817. Matchsticks to Square (Backtracking)

HardRecursionRecursion

Given an array of matchstick lengths, determine if you can form a perfect square using ALL matchsticks. Return true/false.

Input: An integer array.

Output: Boolean.

Examples

Example 1
Input: [1,1,2,2,2]
Output: true
Explanation: Side=2: (2),(2),(1,1),(2).
Example 2
Input: [3,3,3,3,4]
Output: false
Explanation: Sum=16, side=4, but 4 is a single stick and we can't split 3+?=4 leftover.

Constraints

Asked by

MetaGoogleAmazon
Solve this problem in the editor →