Created
November 15, 2016 04:49
-
-
Save SahilKadam/6f3547ce4723579e05d40754d6254c27 to your computer and use it in GitHub Desktop.
A left rotation operation on an array of size shifts each of the array's elements unit to the left. For example, if left rotations are performed on array , then the array would become . Given an array of integers and a number, , perform left rotations on the array. Then print the updated array as a single line of space-separated integers.
This file contains 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 array_left_rotation(a, n, k): | |
if k % n == 0: | |
return a | |
else: | |
return (a[k%n: ] + a[ :k%n]) | |
n, k = map(int, input().strip().split(' ')) | |
a = list(map(int, input().strip().split(' '))) | |
answer = array_left_rotation(a, n, k); | |
print(*answer, sep=' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment