Build a Square from Sticks
InterviewTime limit1sMemory limit128 MB
Given up to 20 stick lengths, decide whether all sticks can be split into four groups of equal total length.
- Level
Medium6 of 10
- Topics
- Backtracking, Recursion, Sorting, Brute force
- Solved
- No attempts yet
Problem
You are given sticks whose lengths may differ. Determine whether you can use all of the sticks to form the four sides of a square.
A stick cannot be cut, each stick must belong to exactly one side, and the four sides must have equal length. In other words, a square can be formed if and only if the sticks can be split into four groups whose length sums are all equal.
Input
The first line contains the number of test cases . Each test case is given on a single line. The first integer on that line is the number of sticks (). It is followed by space-separated integers giving the stick lengths, where each length is a natural number between and inclusive.
Output
For each test case, print yes on its own line if all the sticks can be used to form a square, or no otherwise.