Check out example codes for "variable sized arrays hackerrank solution in c++". It will help you in understanding the concepts better.

Code Example 1

#include <iostream> #include <vector>  using namespace std;  int main() { 	// get length of array 'a' and number of queries 	int n, q; 	cin >> n >> q;  	// create vector of vectors 	vector<vector<int>> a(n);  	// fill each 2D vector i with k_i values 	for (int i = 0; i < n; i++) { 		// get the length k of the vector at a[i] 		int k; 		cin >> k;  		// fill the vector with k values 		a[i].resize(k); 		for (int j = 0; j < k; j++) { 			cin >> a[i][j]; 		} 	}  	// run queries on a 	for (int q_num = 0; q_num < q; q_num++) { 		// get i, j as the 'query' to get a value from a 		int i, j; 		cin >> i >> j; 		cout << a[i][j] << endl; 	}  	return 0; }</textarea>              <br/>

Code Example 2

int n,q; cin >> n >> q; vector< vector<int> > a(n);  // input each array 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);     } }  // do the queries for (int i=0;i<q;i++) {     int x,y;     cin >> x >> y;     cout << a[x][y] << endl; }

Learn ReactJs, React Native from akashmittal.com