You are viewing a single comment's thread. Return to all comments →
def dynamicArray(n, queries): # Write your code here arr = [0]*n for num in range(n): arr[num] = [] lastAnswer = 0 answers = [] for query in range(len(queries)): if queries[query][0] == 1: idx = (queries[query][1] ^ lastAnswer) % n arr[idx].append(queries[query][2]) elif queries[query][0] == 2: x = queries[query][1] idx = (x ^ lastAnswer) % n y = queries[query][2] lastAnswer = arr[idx][y% len(arr[idx])] answers.append(lastAnswer) return answers
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 →
Python