You are viewing a single comment's thread. Return to all comments →
Here is my c++ solution, you can watch the explanation here : https://youtu.be/MYdQxgmJ4Sk
vector<int> dynamicArray(int n, vector<vector<int>> queries) { int lastAnswer = 0; vector<int> result; vector<vector<int>> arr(n); for(auto query: queries) { int type = query[0], x = query[1], y = query[2]; int idx = (x ^ lastAnswer) % n; if(type == 1) { arr[idx].push_back(y); } else { lastAnswer = arr[idx][y % arr[idx].size()]; result.push_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 →
Here is my c++ solution, you can watch the explanation here : https://youtu.be/MYdQxgmJ4Sk