Huffman Encoding (Design)

Given characters and their frequencies, design a Huffman coding and encode a given string optimally (theoretical problem).

Input Format

N/A (design question).

Output Format

N/A.

Constraints

Examples

Example 1:

Input:

0 = "a"
1 = "a"
2 = "a"

Output:

000

Explanation:

Single symbol 'a' — Huffman code is 0, encoded = 000

Example 2:

Input:

0 = "a"

Output:

0

Explanation:

Single symbol single char — code 0

Example 3:

Input:

0 = "a"
1 = "a"
2 = "a"
3 = "a"

Output:

0000

Explanation:

Single symbol 4 times — 0000

Loading...
Huffman Encoding (Design) - Strings DSA Problem