So, I am given N numbers of Sticks, and each of them has length l(assume all lengths are whole number). How do I come up with an algorithm that would sort out all 6 combination of sticks that would make up a square shape.
I assume that l_i is the longest stick, that means the biggest square exists in that population would have a perimeter of 4*l_i.
And the small square exist that is made of 6 sticks would have a perimeter of 8, because the shortest stick is 1, and 6 sticks that makes the smallest square would have the length of (1,1,1,1,2,2)
Then I am still puzzled in creating an algorithm that would solve this problem in a clean way.
I first attempted using brute force method, say to find all the possible N choose 6 combination, then to check each one of them to sort out the legit combinations, but this method is a very heavy computation and it's not practical when n is very large.
Would you have some advice for me to handle this in a better way?