Algorithm · Square · Medium
You are given an input string. Implement a simple compression pipeline in the spirit of Huffman coding, built up in stages: Frequency counting: Tally the number of occurrences of every letter in the string. Tree construction: Using those tallies, assemble a tree in the style of a Huffman tree. Code assignment: Walk the tree with a depth-first traversal to determine a binary code for each character. Encoding: Use the resulting codes to translate the original string into its…