Problem 14 of 75

Maximum Average Subarray I

EasyNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

You are given an integer array nums of n elements and an integer k. Find a contiguous subarray of length exactly k that has the maximum average value, and return this value (answers within 10⁻⁵ are accepted).

([1,12,-5,-6,50,3], 4) → 12.75

Your solution runs against 3 unit tests, including edge and large-value cases.

Loading...

Test console · 3 unit tests

Submit your code to run it against all 3 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Maximum Average Subarray I, explainedGreg Hogg