Sort by

recency

|

2078 Discussions

|

  • + 0 comments

    It appears that result comparison for all the test cases is not correct. I implemented as the problem defined. For me only test cae 10 is successful and all other is failing. But when I use Test Case 1 input data as custom input, result is successful.

  • + 0 comments

    Thank you to the comments that explained the missing parts of the question.

  • + 0 comments
    def dynamicArray(n, queries):
        # Write your code here
        # Initialize n empty arrays
        arr = [[] for _ in range(n)]
        last_answer = 0
        answers = []
        
        for query in queries:
            query_type = query[0]
            x = query[1]
            y = query[2]
            
            if query_type == 1:
                # Query type 1: Append y to arr[idx]
                idx = (x ^ last_answer) % n
                arr[idx].append(y)
                
            elif query_type == 2:
                # Query type 2: Get value and update last_answer
                idx = (x ^ last_answer) % n
                # Get the element at position y % size in arr[idx]
                element_idx = y % len(arr[idx])
                last_answer = arr[idx][element_idx]
                answers.append(last_answer)
        
        return answers
    
  • + 0 comments

    The problem definition is incorrect.

  • + 3 comments

    The problem definition is incorrect.

    It states that: idx = (x ⊕ lastAnswer)

    But it should read: idx = (x ⊕ lastAnswer) % n

    where n is one of the input variables.