We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
intmain(){unsignedintarrCount,queryCount;cin>>arrCount>>queryCount;vector<vector<unsignedint>>numArrs(arrCount);unsignedintarrSize=0;unsignedintarrVal=0;// Input all number arraysfor(inti=0;i<arrCount;i++){cin>>arrSize;for(intj=0;j<arrSize;j++){cin>>arrVal;numArrs[i].push_back(arrVal);}}unsignedintwhichArr,indexArr;// Query the arrays// Query = [arr_num, arr_idx]for(inti=0;i<queryCount;i++){cin>>whichArr>>indexArr;cout<<numArrs[whichArr].at(indexArr)<<'\n';}return0;}// TIME COMPLEXITY// Input phase: O(N)// Query phase: O(Q) as .at() is constant// SPACE COMPLEXITY// O(N) - took no location of array in memory
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Variable Sized Arrays
You are viewing a single comment's thread. Return to all comments →