title: Iteration in Pointer to Pointer 2-d Array
body: <p>I'm doing this challenge on Hackerrank and I've tried all I could do but didn't get it right.
  The challenge details are: <a href="https://www.hackerrank.com/challenges/dynamic-array/problem" rel="nofollow noreferrer">https://www.hackerrank.com/challenges/dynamic-array/problem</a></p>
  
  <p>My Code is:</p>
  
  <pre><code> #include &lt;cmath&gt;
  #include &lt;cstdio&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  
  int main() {
      /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
      int noOfSequence, noOfQuery;
      int lastAnswer = 0, j=0;
      int query, x, y;
  
      cin&gt;&gt;noOfSequence&gt;&gt;noOfQuery;
  
      int *seqLength = new int[noOfSequence];
      for(int i=0; i&lt;noOfSequence; i++){
          seqLength[i] = 0;
      }
  
      int **seqList = new int*[noOfSequence];
      for(int i=0; i&lt;noOfSequence; i++){
          seqList[i] = new int [noOfSequence];
      }
  
      for(int i=0; i&lt;noOfQuery; i++){
          cin&gt;&gt;query&gt;&gt;x&gt;&gt;y;
          switch(query){
              case 1: {
                          int seqListIndex = (x ^ lastAnswer) % noOfSequence;
                          *(seqList[seqListIndex] ++) = y;
                          seqLength[seqListIndex] += 1;
                          break;
                      }
              case 2: {
                          int seqListIndex = (x ^ lastAnswer) % noOfSequence;
                          lastAnswer = seqList[seqListIndex][y%seqLength[seqListIndex]];
                          cout&lt;&lt;lastAnswer;
                          break;
                      }
              default: cout&lt;&lt;"default"&lt;&lt;endl;
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>1. <code>int **seqList</code> is a pointer to an array of pointers. The array of pointers are further pointing towards the individual arrays of <code>int</code>.</p>
  
  <p>2.<code>int *seqLength</code> is a pointer to array of intergers. This array of integers is keeping track of the length of arrays mentioned above.
  3.<code>int seqListIndex</code> denotes the index of the array of pointers.</p>
  
  <p>I guess there's something wrong with the way the <code>lastAnswer</code> is computed.I've checked it in every possible way i can but still couldn't find anything.
  I've also tried to understand how we iterate over the int array but a little more knowledge would be great. </p>