You are viewing a single comment's thread. Return to all comments →
Python 3 solution
def dynamicArray(n: int, queries: list[list[int]]) -> list[int]: arr: list[list[int]] = [[] for __ in range(n)] lastAnswer = 0 answers: list[int] = [] save_answer = answers.append for query in queries: subarray = arr[(query[1] ^ lastAnswer) % n] if query[0] == 1: subarray.append(query[2]) continue save_answer(lastAnswer := subarray[query[2] % len(subarray)]) 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 3 solution