15% off all plans & roadmaps Use code
See plansLeetCode 643 · Solution & editorial
You are given an integer array nums consisting of n elements, and an integer k.
Maximum Average Subarray I is a Sliding Window problem, in the Fixed Size (Subarray Calculation) subpattern. The pattern covers fixed-size, variable-size, and character frequency matching window techniques
Learn fixed-size sliding window for subarray calculations like maximum average, moving average, and k-size subarray problems.
The reference solution runs in O(n) time and O(1) space.
Maximum Average Subarray I has been reported in interviews at Amazon.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Maximum Average Subarray I is a Sliding Window problem, in the Fixed Size (Subarray Calculation) subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.