Dashboard
LC #643
Maximum Average Subarray I
Pattern · ?AmazonGoogle
Problem
Given an integer array nums and integer k, find a contiguous subarray of exactly length k that has the maximum average value, and return that value.
Constraints
- 1 ≤ k ≤ n ≤ 10⁵
- -10⁴ ≤ nums[i] ≤ 10⁴
Example
- Input
- nums = [1, 12, -5, -6, 50, 3], k = 4
- Output
- 12.75
- Why
- [12, -5, -6, 50] → sum = 51, avg = 51/4 = 12.75
Spot the pattern
Which pattern cracks it?
Hints
One at a time