Distinct workout types per window
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].
Implement
distinct_per_window(types: list[int], k: int) → list[int]Examples
in
[[1,2,1,3,3],3]out[2,3,2]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 13 min
solution.py
InputExpectedGot
[[1,2,1,3,3],3][2,3,2]not run yetsample