Skip to content
Advertisement

understanding the cyclic rotation codility challenge?

I want to start by saying thank you for the help first.

I am tackling the cyclic rotation problem where you have to shift the contents of an list/array to the right and effectively wrapping the elements around so for example:

For example, given

JavaScript

the function should return [9, 7, 6, 3, 8]. Three rotations were made:

JavaScript

my code is as follows:

JavaScript

after 3 rotations I get the list as A = [8, 9, 7, 6, 3] so to me it appears to place the last element from A to the front of the new_list.

So any help or points in the right direction would be helpful thank you again.

Advertisement

Answer

So I realised I only had to loop around K times and check for an empty list. And what I got in the end is:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement