Most Distinct Window — Solution & Editorial
Maintain a frequency map while sliding; the map's size is the window's distinct count. Delete keys that drop to zero.
Complexity: O(N)
Watch out: Forgetting to erase zero-count keys makes the map size overcount distinct values.