hash_table.state
Input
Hash table
Current look-up
Match / window
Stored entry
What is Distinct Count in a Window
Slide a window of size k across the array and report how many unique values sit inside it. A frequency map is the window’s memory: increment the entering value, decrement the leaving value, and delete a key when its count hits 0. The answer each time is len(freq).
k-1 every step both adds and removes one element.1, 2, 1, 3, 4, 2, 3, k = 4. Windows produce distinct counts 3, 4, 4, 3.Interactive trace
Pseudocode & Complexity
| Operation | Time |
|---|---|
| Each enter / leave | O(1) expected |
| Full scan | O(n) |
| Space | O(n) |
Python implementation