Connect all sticks into one. Cost to connect two sticks equals their sum. Minimize total cost.
Use a min-heap. Always combine the two smallest sticks to minimize cost.
- Add all sticks to a min-heap
- While heap has more than 1 element
- Poll two smallest sticks, compute sum
- Add sum back to heap, add to total cost
- Return total cost
- Time Complexity: O(n log n)
- Space Complexity: O(n)