The first line contains an integer 'T', denoting the number of test cases. The 'T' test cases follow.
The first line of each test case contains an integer N, the size of the array.
The second line of each test case contains N space-separated integers.
For each test case, print the rearranged array as described in the problem statement.
You don’t need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10^2
1 <= N <= 10^4
0 <= ARR[i] <= N-1
Where 'ARR[i]' is 'ith' element of ARR.
Time Limit : 1 sec
As we are not allowed to use any extra space, we need to find an array element that can store two values at the same time. To do so, we increment every element at the ith index by (arr[arr[i]]%N)*N. Now after this increment every element is now holding two values, the old value and the new value. The old value can be obtained by arr[i]%N and the new value can be obtained by arr[i]/N. Let us understand how this is achieved.
Now let’s see how to reach the solution to our problem.
Missing Number
Longest Subarray With Zero Sum
Merge Two Sorted Arrays Without Extra Space
Ninja And The Strictly Increasing Array
Negative To The End