The value of K varies from array to array. How to do this?
This is what I have to achieve. Its the hackerrank variable sizedarray question. https://s3.amazonaws.com/hr-challenge-images/14507/1476906485-2c93045320-variable-length-arrays.png
I've read the solutions but am unable to understand it. Please explain this line of code : int** seq=new int* [n];
Following is the complete code from which the snippet has been taken.
int main()
{
int n,q;
cin>>n>>q;
int** seq=new int* [n];
for(int i=0;i<n;i++)
{
int a;
cin>>a;
int* b=new int [a];
for(int j=0;j<a;j++)
{
int e;
cin>>e;
b[j]=e;
}
*(seq+i)=b;
}
for(int i=0;i<q;i++)
{
int r,s;
cin>>r>>s;
cout<<seq[r][s]<<endl;
}
}
I've also read something about using vector to create variable sized array. I don't understand. please explain.