
1. A comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with a nut to see which one is bigger/smaller.
2. The set of Nuts/Bolts will consist of numeric strings that represent their sizes. The size of each nut/bolt will be equal to its numerical value. For example, the size of ‘10’ will be equal to 10.
3. For every bolt, there will exist a nut of the same size.
4. Don’t return or print anything. Modify the original sequence of nuts and bolts such that each nut of a particular size matches its bolt of the same size.
5. Store the matched pair of nuts and bolts in any order.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘3*T’ lines represent the ‘T’ test cases.
The first line of each test case contains an integer ‘N’ denoting the number of nuts/bolts.
The second line of each test case contains ‘N’ space-separated strings denoting the nuts of different sizes.
The third line of each test case contains ‘N’ space-separated strings denoting bolts of different sizes.
For each test case, 2 arrays will be printed on separate lines such that the first array contains the nuts, the second array contains the bolts and the nut present at the ‘ith’ position in the array of nuts should be a perfect match for the bolt present at the ‘ith’ position in the array of bolts.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5 * 10^3
1 <= SIZE <= 10^9
Time limit: 1 second
The idea is to quick sort the two arrays using each other.
Return the index of the pivot in the nuts array. Call it ‘i’.
3. Now, using NUTS[i] as a pivot in the bolts array, partition the bolts array.
4. Recur for [LOW……PIVOT-1] and [PIVOT+1…….HIGH] for nuts and bolts array.
5. Lastly, we get the required pairs.