We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def circularArrayRotation(a, k, queries):
k=k%len(a)
reverse(a,0,len(a)-1)
reverse(a,0,k-1)
reverse(a,k,len(a)-1)
l=[]
for i in queries:
l.append(a[i])
return l
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Circular Array Rotation
You are viewing a single comment's thread. Return to all comments →
def reverse(a,l,r): i=l j=r while i
def circularArrayRotation(a, k, queries): k=k%len(a) reverse(a,0,len(a)-1) reverse(a,0,k-1) reverse(a,k,len(a)-1) l=[] for i in queries: l.append(a[i]) return l