You are viewing a single comment's thread. Return to all comments →
function dynamicArray(n, queries) { // Write your code here let arr = Array.from({ length: n }, () => []); let lastAnswer = 0; let res = [];
queries.forEach(query => { const [t, x, y] = query; const idx = (x ^ lastAnswer) % n; if (t === 1) { arr[idx].push(y); } else if (t === 2) { lastAnswer = arr[idx][y % arr[idx].length]; res.push(lastAnswer); } }); return res;
}
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 →
function dynamicArray(n, queries) { // Write your code here let arr = Array.from({ length: n }, () => []); let lastAnswer = 0; let res = [];
}