Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Hackerrank/Variable Sized Arrays.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*https://www.hackerrank.com/challenges/variable-sized-arrays/problem*/
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
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;
}