You are viewing a single comment's thread. Return to all comments →
Javascript
function dynamicArray(n: number, queries: number[][]): number[] { const arr = new Array(n); let lastAnswer = 0; const answers: number[] = []; queries.forEach(([qType, x, y]) => { const idx = (x ^ lastAnswer) % n; if (!arr[idx]) { arr[idx] = []; } if (qType === 1) { arr[idx].push(y); } else if (qType === 2) { lastAnswer = arr[idx][y % arrSize(arr[idx])]; answers.push(lastAnswer); } }); return answers; }
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 →
Javascript