Reversal algorithm for right rotation of an array
Oct 26, 2020
--
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))