Skip to content

Commit

Permalink
Fast Left Rotation Code
Browse files Browse the repository at this point in the history
  • Loading branch information
akash-salvi authored Oct 1, 2020
1 parent 0e71bf4 commit e573137
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Array/Quickly find multiple left rotations of an array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<bits/stdc++.h>
using namespace std;

// Function to left rotate an array k times
void leftRotate(int arr[], int n, int k)
{
// Print array after k rotations
cout<<"\nAns :"
for (int i = k; i < k + n; i++)
cout << arr[i%n] << " ";
}


int main()
{
int n;
cout<<"Enter Number of Elements in array : ";
cin>>n;

cout<<"\nEnter Elements : ";
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];


int k;
cout<<"Enter number of Left rotations to be performed : ";
cin>>k;
leftRotate(arr, n, k);

return 0;
}

0 comments on commit e573137

Please sign in to comment.