Implement prototype(temps, commands) and solve(temps, commands). Initialize internal values from temps. ["set", index, value] replaces one value; ["min", left, right] queries [left, right). Return only query results in order, null for empty ranges. Negative values are valid.

For [1, 5] and [["min", 0, 2], ["set", 0, 9], ["min", 0, 2], ["min", 1, 1]], return [1, 5, null]. Unknown operation, set index outside [0, n), or a range failing 0 <= left, left <= right, right <= n throws RangeError.

Prototype: copy and scan. Final: segment tree with O(n) construction/space and logarithmic updates/queries. Preserve both inputs and every command record on failure too.

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:

Shell
node main.mjs --stage prototype
node main.mjs --stage final

Edit 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.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.