Fix the burst finder for a queue autoscaler

Review the AI's codeHard40 min

Your task

Your queue autoscaler adds workers when a backlog builds fast. It reads how much the queue's length changed in each minute, and it needs the shortest burst: the fewest consecutive minutes over which the queue grew by at least k items in total.

An assistant wrote shortest_burst(changes, k). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • changes: the change in queue length for each minute, in order. A change is negative when workers cleared more items than arrived.
  • k: how much the queue must grow, at least 1.
  • Return the length, in minutes, of the shortest run of consecutive minutes whose changes add up to at least k, or -1 when no run does.

Rules the tests check:

  • A run is one or more consecutive minutes.
  • Each change is a whole number from -100,000 to 100,000, and k is at most 1,000,000,000.
  • There are at most 200,000 minutes.

Then, in a sentence or two: how would you catch this kind of bug in review?

Examples

shortest_burst(changes: list[int], k: int) -> int
Example 1
Inputshortest_burst([3, 1, 4, 1, 5, 9, 2, 6], 15)
Output3
Example 2
Inputshortest_burst([10, -2, 30, 25], 50)
Output2
Example 3
Inputshortest_burst([2, 3, 1, 2], 20)
Output-1