• + 2 comments

    Hi there friends :)

    This is my first time posting a comment here on this site. I'm currently practicing some python to prepare myself for interview questions! I didn't see any python solutions, for this problem, here on this forum so I figured I'd post what I came up with. If anyone has any questions about how it works, please feel free to ask! :)

    Also, any suggestions on how I could have done it better are also appreciated. Cheers

    # Python3: Dynamic Array
    # created by: Andrew Clark
    N, Q_size = map(int, input().split(" "))
    lastAns = 0
    seqList = []
    
    for i in range(N):
        seqList.append([])
        
    for i in range(Q_size):
        q, x, y = map(int, input().strip().split(" "))
        seq = ((x ^ lastAns) % N)
        if (q == 1):
            seqList[seq].append(y)
        else: # q == 2
            lastAns = seqList[seq][y % len(seqList[seq])]
            print(lastAns)