Minimum Cost to Connect Sticks (Huffman)

Medium · Greedy · about 15 minutes

Asked at Amazon, Google.

You have sticks with positive integer lengths. Connecting two sticks of lengths x and y costs x + y and produces one stick of length x + y. Return the minimum total cost to connect all the sticks into one.

Related guides