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(){introws,q;cin>>rows>>q;vector<vector<int>>matrix(rows);for(inti=0;i<rows;i++){intcols;cin>>cols;matrix[i].resize(cols);for(intj=0;j<cols;j++)cin>>matrix[i][j];}// for query partfor(inti=0;i<q;i++){introw,col;cin>>row>>col;cout<<matrix[row][col]<<endl;}return0;}
Using normal Arrays
intmain(){introws,q;cin>>rows>>q;int**matrix=newint*[rows];// taking inputsfor(inti=0;i<rows;i++){intcols;cin>>cols;matrix[i]=newint[cols];for(intj=0;j<cols;j++)cin>>matrix[i][j];}// for query partfor(inti=0;i<q;i++){introw,col;cin>>row>>col;cout<<matrix[row][col]<<endl;}// delete dynamically allocated memoryfor(inti=0;i<rows;i++){delete[]matrix[i];}delete[]matrix;return0;}
The logic is same TC -> O(n * m) where n is rows and m is columns
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 →
The following include two solutions
The logic is same TC -> O(n * m) where n is rows and m is columns