Prefix Codes, means the codes (bit sequences) are assigned in such a way that the code assigned
Fantastic news! We've Found the answer you've been seeking!
Question:
Input format
First fine: T (Number of test cases)
The first line of each test case contains an integer N represents the number of character in the array
The next line contains N distinct space separated characters
The next line contains the frequency of each character respectively
Output format
For each test case, print the Huffman code for each character of the character array.
Constraints
1 ≤ T ≤ 10^3
1 ≤ N ≤ 26
a ≤ each character of character array ≤ z
1 ≤ frequency of each character ≤ 10^5
Sample Input
1
4
a b c d
5 7 2 9
Sample Output
d: 0
b: 10
c: 110
a: 111
Related Book For
Posted Date: