Solution for Huffman algorithm