variable sized arrays hackkerrank answers code example
Example 1: variable sized arrays hackerrank solution in c++
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<vector<int>> a(n);
for (int i = 0; i < n; i++) {
int k;
cin >> k;
a[i].resize(k);
for (int j = 0; j < k; j++) {
cin >> a[i][j];
}
}
for (int q_num = 0; q_num < q; q_num++) {
int i, j;
cin >> i >> j;
cout << a[i][j] << endl;
}
return 0;
}
Example 2: variable sized arrays hackerrank
int n,q;
cin >> n >> q;
vector< vector<int> > a(n);
for (int i=0;i<n;i++) {
int k;
cin >> k;
for (int j=0;j<k;j++) {
int data;
cin >> data;
a[i].push_back(data);
}
}
for (int i=0;i<q;i++) {
int x,y;
cin >> x >> y;
cout << a[x][y] << endl;
}