I tried to solve the Circular Array Rotation problem on HackerRank. https://www.hackerrank.com/challenges/circular-array-rotation/problem
The following code passes all test cases except case #4, which gets a runtime error. Could someone point out the problem?
def circularArrayRotation(a, k, queries):
if k < len(a):
k = k
elif k == len(a):
k = 0
else:
k = k%a
newList = []
for val in queries:
newInd = -k+val
if abs(newInd) > len(a):
newInd = newInd - (len(a)-1)
newList += [a[newInd]]
else:
newList += [a[newInd]]
return newList