Back to questions

Average Subarray Walmart Python Interview Question

Average Subarray

Walmart Python Interview Question

You are given an integer array consisting of elements, and an integer .

Your task is to find a contiguous subarray of whose length is exactly that has the highest average value. A subarray is simply a sequence of consecutive elements from the original array. After identifying this subarray, return the average value, rounded to two decimal places.

Example #1

Input: nums = [1, 2, -5, -3, 10, 3], k = 3

Output: 3.33

Explanation: The subarray here is , so the average is 3.33.

Example #2

Input: nums = [9], k = 1

Output: 9.00

Explanation: The subarray here is just , so its average is exactly 9.00.

Input

Python

Output