Skip to content

sam-klok/ArraysRotation

Repository files navigation

Hi... I'm getting back to simple algorithmical exercies.
Here I'm giving various solutions, some of them better, in my opinion, than requested by sites like Hacker Rank.

So. The fastest algoritm is with small temp array (size equal to shift). 
The most beautiful algoritm is the slowest. It's algoritm with cyclical shift.
In the middle it the simpliest copy in a new array. Relatively fast, but ugly. 

See performance test.

sam klok



Notes:

Some solutions are on Stack Overflow:
https://stackoverflow.com/questions/38482696/how-to-efficiently-rotate-an-array

See task on Hacker Rank:
https://www.hackerrank.com/challenges/array-left-rotation/problem


A left rotation operation on an array of size  shifts each of the array's elements  unit to the left. Given an integer, 
rotate the array that many steps left and return the result.

Sample Input

5 4
1 2 3 4 5
Sample Output

5 1 2 3 4

About

Arrays Rotation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages