Reversal algorithm for right rotation of an array

Examples:

Input: arr[] = {1, 2, 3, 4, 5, 
6, 7, 8, 9, 10}
k = 3
Output: 8 9 10 1 2 3 4 5 6 7

Input: arr[] = {121, 232, 33, 43 ,5}
k = 2
Output: 43 5 121 232 33

code:

def last_to_first(list_1,n):
list_1 = (list_1[len(list_1) - n:len(list_1)]
+ list_1[0:len(list_1) - n])
return list_1

arr=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
k = 3
print(last_to_first(arr,k))
arr = [121, 232, 33, 43 ,5]
k = 2
print(last_to_first(arr,k))

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sairam Penjarla

Sairam Penjarla

Looking for my next opportunity to make change in a BIG way