Data Structures19 sections · 729 units
Open in Course

Problem - Maximum Average Subarray

Fixed window intro

Given an integer array numsnums and an integer kk, find the contiguous subarray of length kk that has the maximum average value.

You're looking at the simplest fixed-window problem. You maintain the sum of the current window. When sliding, add the new element and subtract the old one. Read the problem. The constraints allow O(n)O(n) but not O(nk)O(nk).