Implement prototype(labels: list[str], limit: int) -> int and solve with the same signature. Return the greatest length of a contiguous range containing at most limit distinct strings. Labels use exact string equality. [] and limit=0 return 0; a negative limit raises ValueError.
Example: (['a', 'a', 'b', 'c', 'b'], 2) returns 3.
Prototype: enumerate ranges and count distinct values. Final: maintain one window and frequency map in expected O(n) time. Do not mutate the input, including when rejecting a negative limit.
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…
Loading editor…
No results yet.
Complete the starter code, then run the checks.
Results and errors will appear here.