We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/*
What we need is an array to store the array pointers.
Another set of arrays to store the numbers
*/
int N , Q, seq_num, num;
cin >> N >> Q;
int size;
//We have N sequences. Thus we need to create an array to hold the array pointers to these sequences.
int **seq_arr ;
seq_arr = new int* [N];
if (seq_arr == NULL) {
cout <<"seq_arr is a NULL pointer" <<endl;
}
//Now, let us store the sequences.
for (int i = 0; i < N; i++) {
cin >>size;
seq_arr[i] = new int[size];
if (seq_arr[i] == NULL) {
cout << "Seq_arr[i] is a NULL pointer." << endl;
}
for (int y = 0; y < size; y++) {
cin >> seq_arr[i][y];
}
}
//Now, Q gives us the number of queries.
for (int i = 0; i < Q; i++) {
cin >> seq_num ;
cin >> num ;
cout << seq_arr[seq_num][num] <<endl;
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Variable Sized Arrays
You are viewing a single comment's thread. Return to all comments →
I did something like this:
}