Implement Huffman encoding for a given text string.
Build a Huffman tree from character frequencies, then compute the total number of bits needed to encode the entire text. Also return the decoded text to verify correctness (it should match the input).
Use a min-heap (priority queue) to build the tree. When frequencies are equal, any tie-breaking order is acceptable as long as the total encoded length is optimal.
Input Specification
A JSON object with key:
"text": string — the text to encode
Example: {"text": "hello world"}
Output Specification
A JSON object with keys:
"encoded_length": integer — total number of bits in the Huffman-encoded string
"decoded": string — the original text (must match input)
Example: {"encoded_length": 32, "decoded": "hello world"}