For a given array I want to perform a number of right circular rotations. For instance given array [1, 2, 3] and number of rotation as 2, I want to obtain [2, 3, 1].
For that I have written the a code in Python given below. I have also looked into the solution given in here. However I am looking for an elegant algorithm that can perform it more efficiently using native data structure in Python.
Here is my code:
def circularArrayRotation(a, k):
for i in range(k):
temp = [0]*len(a)
for j in range(len(a)-1):
temp[j+1] = a[j]
temp[0] = a[len(a)-1]
a = temp
a = [1,2,3]
k = 2
dequefrom the collections module?