Dynamic Array

  • + 0 comments
    def dynamicArray(n, queries):
        answers = [0]
        arr = [[] for i in range(n)]
    
        for q in queries:
            idx = (q[1] ^ answers[-1]) % n
            if q[0] == 1:
                arr[idx].append(q[2])
            else:
                answers.append(arr[idx][q[2] % len(arr[idx])])
    
        return answers[1:]