Back to course home
0% completed
Maximum Average Subarray I (easy)
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
.
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible