HackerRank variable sized arrays solution c++ explained

Variable Sized Arrays, is a HackerRank problem from the Introduction subdomain of the C++ coding section. This article will explain how you can solve the ‘HackerRank variable sized arrays solution c++’ and explain it stepwise for your better understanding.

variable sized arrays solution c++

Problem statement

Consider an n-element array, where each index a in the array contains a reference to an array of integers where the value varies from array to array…

You can check out the complete problem on Variable sized Arrays at HackerRank.

The below-given code snippet is the solution to the problem. Mind scrolling further below if you’re looking for an explanation of the following snippet.

Related: Top 5 tech skills that you can learn


Variable Sized Arrays

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int x, y, s= 0;
    cin >> x >> y;
    int *arr[x];
        int num;
        cin >> num;
        arr[s] = new int[num];
        for(int i=0; i<num; i++){
        int a,b;
        cin >> a>>b;
        cout << arr[a][b]<< endl;
    return 0;
Sharing Is Caring:
Editorial Staff

An aspiring BTech Electronics and Communication student, obsessed with Coding, Gadgets, Blogging, & Digital Marketing.

Leave a Comment