You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )
std::vector<int> dynamicArray( int const & _n , std::vector<std::vector<int>> const & _queries ){ using namespace std; auto lastAnswer = 0; auto idx = -1; auto result = vector<int>(); auto matrix = vector<vector<int>>(_n); for(auto & query : _queries){ if(query.at(0) == 1){ matrix.at((query.at(1) ^ lastAnswer) % _n) .emplace_back(query.at(2)); }else{ idx = (query.at(1) ^ lastAnswer) % _n; lastAnswer = matrix.at(idx).at(query .at(2) % matrix.at(idx).size()); result.emplace_back(lastAnswer); } } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Dynamic Array
You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )