FunctionRacerProblemsRace

Maximum Average Subarray

EasyTwo pointersPython, JavaScript, TypeScript, Java, C++

Look at every stretch of exactly k consecutive items in nums. Return the largest average among them as a float.

Example 1

nums [1,12,-5,-6,50,3]
k 4
returns 12.75

The stretch [12, -5, -6, 50] has sum 51, average 12.75.

Example 2

nums [5]
k 1
returns 5.0

One window, average 5.0.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Two pointers problems