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.
This is my answer matched with a few people and it is alright but does not pass all testy cases. Can someone help
def dynamicArray(n, queries):
arr=[[] for _ in range(n)]
lastAnswer=0
ans=[]
for i in queries:
idx=(i[1]^lastAnswer)%n
if i[0]==1:
arr[idx].append(i[2])
elif i[0]==2:
v=i[2]%len(arr[idx])
lastAnswer=arr[idx][v]
ans.append(lastAnswer)
return(ans)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Dynamic Array
You are viewing a single comment's thread. Return to all comments →
This is my answer matched with a few people and it is alright but does not pass all testy cases. Can someone help
def dynamicArray(n, queries): arr=[[] for _ in range(n)] lastAnswer=0 ans=[] for i in queries: idx=(i[1]^lastAnswer)%n if i[0]==1: arr[idx].append(i[2]) elif i[0]==2: v=i[2]%len(arr[idx]) lastAnswer=arr[idx][v] ans.append(lastAnswer) return(ans)