Problems > Most Distinct Window > Editorial

Most Distinct Window — Solution & Editorial

Back to the Problem

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.