Sort by

recency

|

2060 Discussions

|

  • + 0 comments

    Wrong problem statement when computing idx, and so its misleading.

  • + 0 comments

    public static List dynamicArray(int n, List> queries) { List lastAnswers = new List();

        int lastAnswer = 0;
        List<List<int>> seqList = new List<List<int>>();
    
        for (int i = 0; i < n; i++){
            seqList.Add(new List<int>());
        }
    
        foreach (var query in queries){
            int index = (query[1]^lastAnswer) % n;
    
            if(query.First() == 1){
                seqList[index].Add(query.Last());
            }
            else{
                int x = query.Last();
                int size = seqList[index].Count;
                lastAnswer = seqList[index][x % size];
                lastAnswers.Add(lastAnswer);
            }
        }
    
        return lastAnswers;   
    }
    
  • + 1 comment

    this problem is so confusing to read

  • + 1 comment

    So here's a link to the actual problem on hacker-rank: https://www.hackerrank.com/challenges/dynamic-array/problem?isFullScreen=true It's basically a question about computing queries on a 2 dimensional array. The specific problem is that it tells you how to compute idx wrong: It says: Compute idx = (x XOR lastAnswer) But that seems to be wrong, because if you compute idx that way it results in an index error even if you do everything correctly. On their own sample desk checking and explanation, they also don't compute idx that way. The way they actually compute it is (you can check Query 3 and Query 4 at the end): idx = (x XOR lastAnswer) % n I'm convinced they got this part wrong in the problem description. But I'm here to learn so I may be the one who either didn't understand the question correctly or I'm missing something. That's why I thought to just ask the community.

  • + 0 comments

    what is the takeaway in this question? Does it have some hidden logic that helps in solving other problems?