Distinct workout types per window

Write codeEasy13 min

Your task

A training app tags each day with a workout-type id (integers; 1 = run, 2 = lift, and so on). For a weekly variety report, it needs the number of distinct workout types in every window of k consecutive days. Given the ids list types and k (1 <= k <= number of days), return a list with one distinct-count per window, in order. Update a count map as the window slides, do not rescan each window. Example: types = [1, 2, 1, 3, 3], k = 3 gives [2, 3, 2].

Examples

distinct_per_window(types: list[int], k: int) -> list[int]
Example 1
Inputdistinct_per_window([1, 2, 1, 3, 3], 3)
Output[2, 3, 2]