Last active
November 24, 2016 14:06
-
-
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.
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
# 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