You are viewing a single comment's thread. Return to all comments →
my code in javascript
function dynamicArray(n, queries) { let arr = new Array(n).fill().map(() => []); let lastAnswer = 0; const answer = []; queries.forEach((query) => { const [type, x, y] = query; const idx = (x ^ lastAnswer) % n; if (type === 1) { arr[idx].push(y); } else if (type === 2) { const size = arr[idx].length; if (size !== 0) { lastAnswer = arr[idx][y % size]; answer.push(lastAnswer); } } }); return answer; }
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 →
my code in javascript