dsa9 min read
Minimum Cost to Connect Sticks — Huffman Coding with a Min-Heap
Find the minimum cost to connect all sticks by always merging the two shortest first — a direct application of the Huffman coding greedy principle, asked at Amazon and Facebook as a clean demonstration of optimal merge order.
Read →