arrayscomplexityhashing
At most k distinct values with a moving window
Anonymous
For a window with at most k distinct values, keep counts and a left edge. Add the next value; while the count of distinct values exceeds k, remove from the left and delete counts that reach zero. Each item enters and leaves once, so the scan is O(n) with expected O(1) hash-map operations.
0