BackeasySliding Window Amazon

Max Average Subarray Solution

Problem Statement

A nutritionist measures daily calorie intake for K consecutive days. Find the maximum average daily intake over any K-day window. Return the value multiplied by 100000 (truncated).

Example 1
Input
[100, 200, 300, 400, 500]
Output
41666

Explanation: Step-by-step: 1. Calculate the sum of the array: 100 + 200 + 300 + 400 + 500 = 1500. 2. Calculate the average: 1500 / 5 = 300. 3. Multiply the average by 100000 and truncate: 300 * 100000 = 30000000, truncated to 41666.

Example 2
Input
[1, 2, 3, 4, 5]
Output
30000

Explanation: Step-by-step: 1. Calculate the sum of the array: 1 + 2 + 3 + 4 + 5 = 15. 2. Calculate the average: 15 / 5 = 3. 3. Multiply the average by 100000 and truncate: 3 * 100000 = 300000, truncated to 30000.

Constraints

  • 1 <= k <= n <= 10^5
  • -10^4 <= arr[i] <= 10^4
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free