Problem 306830 · easy · Phase 03 Linear Management & Searching

Quietest Stretch

sliding window · fixed-size window · running sum

A microphone logs a noise level every minute in noise. You want the quietest block of exactly k consecutive minutes. Return the start index of the length-k window with the smallest total noise. If several windows tie, return the smallest start index.

Examples

Input:  noise = [8, 3, 5, 2, 9], k = 2
Output: 2
Explanation: window sums are 11, 8, 7, 11; the smallest (7) starts at index 2.

Input:  noise = [4, 4, 4], k = 3
Output: 0

Constraints

  • 1 <= k <= len(noise) <= 10**5
  • -10**6 <= noise[i] <= 10**6
  • Target complexity: O(n) time. Re-summing every window (O(n·k)) is too slow for the largest tests.

Goals

  • Maintain a running window sum by adding one element and removing one
  • Track the best window's start index with an earliest-wins tie rule
Starting Python…