You are viewing a single comment's thread. Return to all comments →
tedious reading and from 1st attempt voila: c++
vector<int> dynamicArray(int n, vector<vector<int>> queries) { vector<int> a; vector<vector<int>> arr(n, vector<int>()); int lastAnswer = 0; for (const auto& q : queries) { const int idx = (q[1] ^ lastAnswer) % n; if (q[0] == 1) { arr[idx].push_back(q[2]); } else { lastAnswer = arr[idx][q[2] % arr[idx].size()]; a.push_back(lastAnswer); } } return a; }
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 →
tedious reading and from 1st attempt voila: c++