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 (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