variable sized arrays hackerrank solution in c++
C++
#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;
}
Also in C++:
- Title
- binary tree search
- Category
- C++
- Title
- c++ ros publisher
- Category
- C++
- Title
- function for searching in map in c++
- Category
- C++
- Title
- how to get input from the console in c++
- Category
- C++
- Title
- Find the minimum difference between pairs in a simple path of tree C++
- Category
- C++
- Title
- cin.ignore
- Category
- C++
- Title
- how to remove maximum number of characters in c++ cin,ignore
- Category
- C++
- Title
- matrix transpose tiling
- Category
- C++
- Title
- quick sort predefined function in c++
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- Operator overloading in C++ Programming
- Category
- C++
- Title
- how to iterate through array in c++
- Category
- C++
- Title
- c++ typedef
- Category
- C++
- Title
- cpp create lambda with recursion
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- find in set of pairs using first value cpp
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++
- Title
- opencv compile c++
- Category
- C++
- Title
- c++ dereference a pointer
- Category
- C++
- Title
- how to convert a string to a double c++
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- map insert c++
- Category
- C++
- Title
- C++ cin cout
- Category
- C++
- Title
- c++ code 2d block
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- vector stl c++
- Category
- C++
- Title
- how the theam are store in database
- Category
- C++
- Title
- c++ sort
- Category
- C++
- Title
- c++ random numbers
- Category
- C++
- Title
- remove item from layout
- Category
- C++
- Title
- how to declare a vector in c++
- Category
- C++
- Title
- c++ looping through a vector
- Category
- C++
- Title
- Combination Sum
- Category
- C++
- Title
- findung the mode in c++
- Category
- C++
- Title
- constant variables in c++
- Category
- C++
- Title
- how to sort a vector in c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- capitalize first letter c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- C++ Syntax
- Category
- C++
- Title
- repeating character in c++
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- c++ short if
- Category
- C++
- Title
- how to find hcf in c++
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- how to create object in c++
- Category
- C++
- Title
- c++ find prime numbers
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- program to know if a number is prime
- Category
- C++
- Title
- basic ex of maps in c++
- Category
- C++
- Title
- sum of integer in array c++
- Category
- C++
- Title
- c++ variable arguments
- Category
- C++
- Title
- How to traverse in a tree iterative C++
- Category
- C++
- Title
- how to compile opencv c++ in ubuntu
- Category
- C++
- Title
- c++ convert int to cstring
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- Runtime Error: Runtime ErrorBad memory access (SIGBUS)
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- properties of a set c++
- Category
- C++
- Title
- c++ random
- Category
- C++
- Title
- how to switch to another branch in git
- Category
- C++
- Title
- kruskal's algorithm c++ hackerearth
- Category
- C++
- Title
- COnvert string to char * C++
- Category
- C++
- Title
- set c++
- Category
- C++
- Title
- find in string c++
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- how to decalre a string in c++
- Category
- C++
- Title
- modular exponentiation c++
- Category
- C++
- Title
- print type cpp
- Category
- C++
- Title
- c++ typeid get type name
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- nginx linux
- Category
- C++
- Title
- ternary operator c++
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- compare string c++
- Category
- C++
- Title
- All palindromic substrings
- Category
- C++
- Title
- c++ string
- Category
- C++
- Title
- heap sort
- Category
- C++
- Title
- singleton c++
- Category
- C++
- Title
- bellman ford algorithm cp algorithm
- Category
- C++
- Title
- Shortest Distance in a Maze
- Category
- C++
- Title
- euler phi gfg
- Category
- C++
- Title
- monotonic deque
- Category
- C++
- Title
- split string at index c++
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- iterative inorder traversal
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- loop through words in string c++
- Category
- C++
- Title
- c++ uint32_t
- Category
- C++
- Title
- first fit algorithm
- Category
- C++
- Title
- sleep system function linux c++
- Category
- C++
- Title
- c++ transform
- Category
- C++