Code Room
CodingEasycod-g1429
Subject Sliding windowLevel Entry–Mid~13 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.