Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

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 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.

Click here to view old Disqus comments.

Login to report an issue on this page.

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

YesLoading...

Subarray with least average

...