Skip to content

Instantly share code, notes, and snippets.

@harsh-2024
Created September 17, 2022 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harsh-2024/419528a5cc0296cca30735ca01f00997 to your computer and use it in GitHub Desktop.
Save harsh-2024/419528a5cc0296cca30735ca01f00997 to your computer and use it in GitHub Desktop.
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void rev(int A[],int s, int e)
{
int i = s;
int j = e;
while(1)
{
if(i == j)
{
break;
}
else if(j == i+1)
{
swap(A[i],A[j]);
break;
}
else
{
swap(A[i],A[j]);
i+=1;
j-=1;
}
}
}
int main() {
int N,D;
cin>>N>>D;
int A[N];
for(int i=0;i<N;i++)
{
cin>>A[i];
}
if(D>N)
{
D = D-N;
}
if(N !=D)
{
rev(A,0,D-1);
rev(A,D,N-1);
rev(A,0,N-1);
}
for(int i=0;i<N;i++)
{
cout<<A[i]<<" ";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment