Implement prototype(values, commands) and solve(values, commands) using internal state initialized from values. Commands are arrays: ["add", index, delta] adds delta, and ["sum", left, right] queries [left, right). Return only sum results in command order. Negative values/deltas and empty ranges are valid.
For [2, 4, 6] with [["sum", 0, 3], ["add", 0, -5], ["sum", 0, 2]], return [12, 1]. Throw RangeError for unknown operations, add index outside [0, n), or any range failing 0 <= left, left <= right, right <= n.
Prototype: copy and scan. Final: a Fenwick tree with logarithmic operations. Preserve values and all commands, including on failure. Array lengths are less than 2^31 for low-bit index operations; this bound applies to indices, not numeric sums.
All numeric inputs and finite arithmetic results in this lesson are safe-integer Numbers. Use null for documented absence, not undefined or a numeric sentinel. Return actual booleans where the contract requires them. Do not add validation requirements beyond the documented inputs.
Run with Node.js 20+ from this directory:
node main.mjs --stage prototype
node main.mjs --stage finalEdit exercise.mjs; keep main.mjs unchanged. Both stages begin as unfinished learner functions. The website uses the same test functions in a separate browser worker. Tests check deterministic examples, boundaries, documented validation, input preservation, and stage-specific cases. Passing tests does not prove the required time complexity.
Complete the starter code, then run the checks.
Results and errors will appear here.