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