Participate in Codex, Test Your Skills & Win BIG

Rearrange Array

Rearrange a given array so that Arr[i] becomes Arr[Arr[i]] with O(1) extra space.


Input : [1, 0]
Return : [0, 1]

Lets say N = size of the array. Then, following holds true :

  • All elements in the array are in the range [0, N-1]
  • N * N does not overflow for a signed integer
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Rearrange Array on Interview Code Editor
  • Hint 1
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions