Skip to content

Instantly share code, notes, and snippets.

@mk6619
Created December 4, 2019 13:26
Show Gist options
  • Select an option

  • Save mk6619/2d837e53d3c5421c94e7a52d07640f24 to your computer and use it in GitHub Desktop.

Select an option

Save mk6619/2d837e53d3c5421c94e7a52d07640f24 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void printArrayReverse(int arr[], int start, int end) {
for(int i = end ; i >= start; i--) {
cout<<arr[i]<<" ";
}
}
int main() {
//code
int testCases;
cin>>testCases;
for(int i = 0 ; i < testCases; i++) {
int n,k;
cin>>n;
cin>>k;
int arr[n];
for(int j =0 ; j < n ; j++) {
cin>>arr[j];
}
int p = k-1, q = 0;
while(p < n ){
printArrayReverse(arr, q, p);
q+=k;
p+=k;
}
printArrayReverse(arr,q, n-1);
cout<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment