Best goal hit window

Write codeEasy10 min

Your task

A habit tracker stores, for each day, a 1 if the user hit their step goal and a 0 if not. For a k-day challenge recap (1 <= k <= number of days), the app shows the best window: the maximum number of goal-hit days in any k consecutive days. Given the binary list flags and k, return that maximum. Example: flags = [0, 1, 1, 1, 0, 1], k = 3 gives 3 (days 1 through 3).

Examples

max_goal_days(flags: list[int], k: int) -> int
Example 1
Inputmax_goal_days([0, 1, 1, 1, 0, 1], 3)
Output3