• + 0 comments

    i had a problem with the variable idx, the problem says about calculate two idx, the first in the query one (idx = (x ^ last_answer)) and the second in query two (idx = (x ^ last_answer) % n) i solve the problem with variable idx = (x ^ last_answer) % n in the up of my for cycle and delete other idx code:

    def dynamicArray(n, queries): array_2D = [] last_answer = 0 results = [] for i in range(len(queries)): array_2D.append([]) for types,x,y in queries: idx = (x ^ last_answer) % n if types == 1: #idx = (x ^ last_answer) array_2D[idx].append(y) else: #idx = (x ^ last_answer) % n last_answer = array_2D[idx][y % len(array_2D[idx])] results.append(last_answer) return results

    result = dynamicArray(2, [[1,1,1],[1,1,7],[1,0,3],[2,1,0],[2,1,1]]) 
    for i in result:
        print(i)