X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Subarray with least average
Easy Accuracy: 34.67% Submissions: 1705 Points: 2

Given an array of size n, Find the subarray with least average of size k.

 

Example 1:

Input: nums = [30, 20, 10], k = 1
Output: 3
Explanation: Subarrays of length 1 are
{30}, {20}, {10}. {10} has the least 
average.

Example 2:

Input: nums = [30, 20, 10], k = 2
Output: 2
Explanation: Subarrays of length 2 are
{30, 20}, {20, 10}. {20, 10} has the least 
average.

 

Your Task:
You don't need to read or print anything. Yous task is to complete the function least_average() which takes the array and k as input parameter and returns the index of the first element of the subarray(1-based indexing) of size k that has least average.

 

Expected Time Complexity: O(n)
Expected Space Compelxity: O(1)

 

Constraints:
1 <= k <= n <= 100000
1 <= elements of array <= 1000000

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Subarray with least average

Output Window