Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Maximum Average Subarray I (easy)
On this page

Problem Statement

Examples

Try it yourself

Problem Statement

Given an array of integers and an integer k, find a contiguous subarray of length k that has the highest average value, and return this maximum average value.

Examples

Example 1

  • Input: nums = [1, 2, 3, 4, 5, 6], k = 2
  • Expected Output: 5.5
  • Justification: The subarray [5, 6] has the highest average (5 + 6) / 2 = 5.5.

Example 2

  • Input: nums = [0, 1, 1, 3, -1, 10, -2], k = 3
  • Expected Output: 4.0
  • Justification: The subarray [3, -1, 10] has the highest average (3 + (-1) + 10) / 3 = 4.0.

Example 3

  • Input: nums = [-5, -2, 0, 3, 9, -1, 2], k = 4
  • Expected Output: 3.25
  • Justification: The subarray [3, 9, -1, 2] has the highest average (3 + 9 + (-1) + 2) / 4 = 3.25.

Constraints:

  • n == nums.length
  • 1 <= k <= n <= 10<sup>5</sup>
  • -10<sup>4</sup> <= nums[i] <= 10<sup>4</sup>

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Examples

Try it yourself