Created
January 4, 2017 17:31
-
-
Save gbazilio/f01fc335d8ad01e94df6ffd9a98803ab to your computer and use it in GitHub Desktop.
Codility - Cyclic Rotation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(A, K): | |
A_length = len(A) | |
new_A_array = [0] * A_length | |
for index in range(A_length): | |
shift_index = (index+K) % A_length | |
new_A_array[shift_index] = A[index] | |
return new_A_array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solutionA(A, K): | |
K = K % len(A) | |
new_A_array = A[-K:] + A[:-K] | |
return new_A_array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment