-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRearrange Array.java
More file actions
32 lines (23 loc) · 835 Bytes
/
Rearrange Array.java
File metadata and controls
32 lines (23 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//https://www.interviewbit.com/problems/rearrange-array/
public class Solution {
public void arrange(ArrayList<Integer> A) {
int n = A.size();
int i = 0;
for (i = 0; i < n; i++) A.set(i, A.get(i) + (A.get(A.get(i)) % n) * n );
for (i = 0; i < n; i++) A.set(i, A.get(i) / n);
/* //prev approach
int N = a.size();
HashMap<Integer, Integer> map = new HashMap<>();
for(int i = 0; i < N; i++){
int val = a.get(i);
map.put(i, val);
if(val == i || val >= N)
continue;
if(map.containsKey(val))
a.set(i, map.get(val));
else
a.set(i, a.get(val));
}
*/
}
}