Implement prototype(labels, limit) and solve(labels, limit). Return the greatest contiguous length containing at most limit distinct strings. Empty input or limit 0 returns 0; negative limit throws RangeError.
For ["a", "a", "b", "c", "b"] with limit 2, return 3. Prototype: enumerate ranges and count distinct values. Final: one moving window plus frequencies, expected O(n) time. Preserve labels, including when rejecting a negative limit.
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.