Skip to content

Instantly share code, notes, and snippets.

@SahilKadam
Created November 15, 2016 04:49
Show Gist options
  • Save SahilKadam/6f3547ce4723579e05d40754d6254c27 to your computer and use it in GitHub Desktop.
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.
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