Timer is Running

Huffman Decoding
##### Submissions: 3029   Accuracy: 64.63%   Difficulty: Easy   Marks: 2

Given a encoded binary string and a Huffman MinHeap tree, your task is to complete the function decodeHuffmanData(), which decodes the binary encoded string and return the original string.

Note: Each node of the min heap contains 2 data members, a character and an integer to denote its frequency. The character '\$' is the special character used for internal nodes whose min heap node only need a integer field.

Example 1:

```Input :
binaryString =
0000000000001100101010101011111111010101010
Min Heap Tree =
\$(20)
/      \
/          \
\$(8)            \
/     \             \
\$(3)      \            \$(12)
/  \       \           /    \
B(1)    D(2)    E(5)    C(6)    A(6)

Output: AAAAAABCCCCCCDDEEEEE

Explanation:
The following chart can be made from the
given min heap tree.
character    frequency    code
A             6        00
B             1        110
C             6        01
D             2        111
E             5        10```

Example 2:

```Input :
binaryString =
01110100011111000101101011101000111
Min Heap Tree =
\$(13)
/        \
/            \
/                \
\$(5)                  \
/      \                  \
/        \                   \
\$(3)         \                  \$(8)
/    \         \                /    \
\$(2)     \         \            \$(4)     \
/   \      \         \          /   \      \
f(1)    o(1)    r(1)    g(2)    k(2)    s(2)    e(4)

Output: geeksforgeeks

Explanation:
The following chart can be made from the
given min heap tree.
character    frequency    code
f             1        0000
o             1        0001
r             1        001
g             2        01
k             2        100
s             2        101
e             4        11```

You dont need to read input or print anything. Complete the function decodeHuffmanData() which takes the root of the Huffman min heap tree and the encoded Binary String as input parameters and returns the decoded string.

Expected Time Complexity: O(N log N)
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ N ≤ 10^3

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Mridul Gupta
Author: harshitsidhwa

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.