Skip to content

Instantly share code, notes, and snippets.

@lazycipher
Created May 5, 2019 05:32
Show Gist options
  • Save lazycipher/beb134ff2ed582858db7cc3d1ff560b6 to your computer and use it in GitHub Desktop.
Save lazycipher/beb134ff2ed582858db7cc3d1ff560b6 to your computer and use it in GitHub Desktop.
Variable Sized Array [HackerRank Practice]
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n, q, indexA, indexI;
//input size of array and no of queries
cin>>n>>q;
vector<int> a[n];
for(int i=0; i<n; i++){
//Get no. of Inputs in ins and get the value of array val.
int ins, val;
cin>>ins;
for(int j=0; j<ins; j++){
cin>>val;
//Push back val to the array at a[i]
a[i].push_back(val);
}
}
for(int i=0; i<q; i++){
cin>>indexA>>indexI;
cout<<a[indexA][indexI]<<"\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment