Longest active streak

Write codeMedium15 min

Your task

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).

Examples

longest_active_stretch(steps: list[int], t: int, k: int) -> int
Example 1
Inputlongest_active_stretch([12000, 4000, 13000, 11000, 3000, 2000, 14000], 10000, 1)
Output4