# Variable Sized Arrays This is the second to last challenge in the Introduction section of C++ at the HackerRank site: https://www.hackerrank.com/challenges/variable-sized-arrays

If interested please take a look at the challenge definition.

Following is a screen capture of the Windows console using the sample data provided in the challenge:

2 2

3 1 5 4

5 1 2 8 9 3

0 1

1 3

My solution written in C++ using Visual Studio 2013 Professional IDE which passed the 11 test cases follows:

#include <iostream>

#include <string>

using namespace std;

/*

*/

int main () {

int           N,

Q;

int           *arr;

int           i,

j,

k;

// **** ****

cin >> N;

cin >> Q;

//     cout << “N: ” << N << ” Q: ” << Q << endl;

// **** load the array ****

for (int n = 0; n < N; n++) {

cin >> k;

//            cout << “k: ” << k << endl;

arr[n] = (int *)calloc(k, sizeof(int));

for (int i = 0; i < k; i++) {

cin >> arr[n][i];

}

}

// **** perform queries ****

for (int q = 0; q < Q; q++) {

cin >> i;

cin >> j;

//            cout << “i: ” << i << ” j: ” << j << endl;

cout << arr[i][j] << endl;

}

// **** ****

return 0;

}

If you have comments or questions regarding this or any other post in this blog or if you have a topic which you would like me to address, please do not hesitate and send me a message via email. I will not disclose your name unless you explicitly all me to do so.

John

john.canessa@gmail.com
{"ft_lang_label":"__label__en","ft_lang_prob":0.6326968,"math_prob":0.6394551,"size":1396,"snap":"2021-43-2021-49","text_gpt3_token_len":416,"char_repetition_ratio":0.109913796,"word_repetition_ratio":0.0,"special_character_ratio":0.38825214,"punctuation_ratio":0.15277778,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9602074,"pos_list":[0,1,2],"im_url_duplicate_count":[null,6,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-27T01:14:35Z\",\"WARC-Record-ID\":\"<urn:uuid:377c558f-e29e-4f13-bf9d-7a908b46a5c2>\",\"Content-Length\":\"36914\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2bd423a7-52d8-4857-b0d3-5ce978c1e72c>\",\"WARC-Concurrent-To\":\"<urn:uuid:1109a200-8d2a-411e-80d4-5ad84190d330>\",\"WARC-IP-Address\":\"208.113.168.135\",\"WARC-Target-URI\":\"https://www.johncanessa.com/2017/01/13/variable-sized-arrays/\",\"WARC-Payload-Digest\":\"sha1:Q2EDLQX6ZT4TMVLRT7GIXJZO67VOO2KR\",\"WARC-Block-Digest\":\"sha1:BRKSWSPYOWHWRERP5CC2KPTP6BGNOMMO\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323587963.12_warc_CC-MAIN-20211026231833-20211027021833-00226.warc.gz\"}"}