-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRearrange_array.cpp
More file actions
43 lines (31 loc) · 1.19 KB
/
Rearrange_array.cpp
File metadata and controls
43 lines (31 loc) · 1.19 KB
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
33
34
35
36
37
38
39
40
41
42
43
// comment :: Rearrange an array in O(1) extra spaces.
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
// int a[n];
while(t--)
{
int n ;
cin>>n;
int arr[n];
for(int m=0;m<=n;m++)
{
cin>>arr[m];
}
for (int i=0; i < n; i++) {
arr[i] += (arr[arr[i]]%n)*n;
}
for (int i=0; i<n; i++){
arr[i] /= n;
}
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
// cout << endl;
}
cout<<endl;
}
return 0 ;
}