If ‘N’ = 5, ‘A’ = {10, 20, 30, 40, 50} and ‘B’ = {20, 10, 40, 50, 30}
Then we will print {1, 0, 4, 2, 3} because:
A[0] occurs at 1st index in array B, A[1] occurs at 0th index, A[2] occurs at 4th index, A[3] occurs at 2nd index, A[4] occurs at 3rd index.
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first line of each test case contains a single integer ‘N’, denoting the number of elements in the array.
The second line of each test case contains N distinct integers ‘A’, denoting the array elements of the first array.
The third line of each test case contains N distinct integers ‘B’, denoting the array elements of the second array.
For each test case, print the index mapping for the two anagram arrays.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 ≤ T ≤ 10
1 ≤ N ≤ 10000
-10^9 ≤ A[i], B[i] ≤ 10^9
Time limit: 1 sec
This is quite an easy problem. All we need to do is to store the elements of array ‘B’ in a hash-map so that the index corresponds to each element is stored in it. Now we can simply iterate through each element in array ‘A’, and find the index corresponding to that element in the hash-map. Here we won’t have to make any additional checks, this is because we are given that both the input arrays are anagrams, so checking for the elements existing in the hash-map will not necessarily be required.
The steps are as follows :