Skip to content

Instantly share code, notes, and snippets.

@NEbere
Last active November 24, 2016 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NEbere/fdfdf18e8db16382257e9c7b020e359d to your computer and use it in GitHub Desktop.
Save NEbere/fdfdf18e8db16382257e9c7b020e359d to your computer and use it in GitHub Desktop.
Given an array of integers and a number, , perform left rotations on the array.
# A left rotation operation on an array of size shifts each of the array's elements 1 unit to the left.
# For example, if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2]
#Given an array of n integers and a number,d , perform d left rotations on the array.
#Then print the updated array as a single line of space-separated integers.
def rotate(array, position):
#print
print (array[position:] + array[:position])
#or return
return array[position:] + array[:position]
rotate([1,2,3,4], 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment