Code Room
CodingMediumcod-g1428
Subject Sliding windowLevel Entry–Mid~15 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A coach reviews a runner’s daily step counts and wants the longest streak of consecutive days that stays "active", tolerating a few off-days: a stretch qualifies if at most k of its days fall strictly below the threshold t. Given steps, t, and k (k >= 0), return the length of the longest qualifying stretch. Example: steps = [12000, 4000, 13000, 11000, 3000, 2000, 14000], t = 10000, k = 1 gives 4 (days 0 through 3).

Implement
longest_active_stretch(steps: list[int], t: int, k: int) → int
Examples
in[[12000,4000,13000,11000,3000,2000,14000],10000,1]out4
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.