Input: A[] = {1, 5, 2, 4, 4, 3}, B[] = {1, 2, 5, 1}
Output: 0 2 1
NA B[0], B[1] and B[2] can be mapped to A[0], A[2] and A[1] respectively but B[3] cannot be mapped to any element of A because the only '1' in A has already been mapped
Input: A[] = {2, 1, 2, 3, 3, 4, 2, 4, 1}, B[] = {1, 2, 5, 1, 2, 4, 2, 3, 2, 1}
Output: 1 0 NA 8 2 5 6 3 NA NA
The idea is to use a hash table where keys are elements of A[] and values are indexes of these elements. Since there can be more than one occurrences of an element, we use a list of items as values in the hash table. Below is the implementation of the above problem: