forked from singh-shreya6/Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse-array-in-groups.cpp
More file actions
50 lines (48 loc) · 963 Bytes
/
reverse-array-in-groups.cpp
File metadata and controls
50 lines (48 loc) · 963 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// GeeksforGeeks Sudo Placement Q 6
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll a[n];
for(ll i=0;i<n;i++)
cin>>a[i];
ll k;
cin>>k;
ll b[n];
for(ll i=0;i<n;i+=k)
{
ll start=i,end=(i+k-1);
if((i+k-1)<n)
{
while(end>=start)
{
b[start]=a[end];
b[end]=a[start];
start++;
end--;
}
}
else
{
ll end=n-1,start=i;
while(end>=start)
{
b[start]=a[end];
b[end]=a[start];
start++;
end--;
}
}
}
for(ll i=0;i<n;i++)
cout<<b[i]<<" ";
cout<<endl;
}
}