# Rearrange Array

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

**Example:**

```
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**

```java
public class Solution {
    public void arrange(ArrayList<Integer> arr) {
        int n = arr.size();
        for (int i = 0; i < n; i++)
            arr.set(i, arr.get(i) + (arr.get(arr.get(i)) % n) * n);
        for (int i = 0; i < n; i++)
            arr.set(i, arr.get(i) / n);
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mayanktyagi3111.gitbook.io/interview-prep/maths/rearrange-array.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
