Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagonal Difference #4

Merged
merged 2 commits into from
Oct 4, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Left Rotation
  • Loading branch information
rohanmittal149 committed Oct 4, 2019
commit 43c96b63fe688ddf829046b42af2513f37400d40
30 changes: 30 additions & 0 deletions Arrays Left Rotation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>

using namespace std;
int main()
{
int n,d;
cin>>n>>d;
int arr[n],p[n];
for(int i = 0; i<n; i++)
{
cin>>arr[i];
p[i] = arr[i];
}
int j = n-d;
for(int i = 0; i<n; i++)
{
if((j+i)<n)
{
arr[j+i] = p[i];
}
else
arr[i-d] = p[i];
}


for(int i = 0; i<n; i++)
{
cout<<arr[i]<<" ";
}
}