Skip to content

Instantly share code, notes, and snippets.

@jcrubino
Created May 2, 2021 18:11
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 jcrubino/cdfacf031797c788a0443e73a6f7fad3 to your computer and use it in GitHub Desktop.
Save jcrubino/cdfacf031797c788a0443e73a6f7fad3 to your computer and use it in GitHub Desktop.
rotation of arrays
def rotate_array_right(array, n):
length = len(array)
remainder = n % length
if remainder == 0:
return array
temp_array = array[0:remainder]
return array[remainder:] + temp_array
def reverse_array(array):
start = 0
end = len(array)-1
reversed_array = []
while end > -1:
reversed_array.append(array[end])
end -= 1
return reversed_array
def rotate_array_left(array, n):
array = reverse_array(array)
return reverse_array(rotate_array_right(array, n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment