Maximum Average Subarray I Problem

Maximum Average Subarray I Problem — ExecCode Easy DSA Practice

Solve the Maximum Average Subarray I problem on ExecCode. Free online easy DSA practice in Sliding Window. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an integer array nums consisting of n elements, and an integer k. Your task is to find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10^-5 will be accepted.

Examples

Input {"nums": [1, 12, -5, -6, 50], "k": 4}; Output 12.75000. Input {"nums": [5], "k": 1}; Output 5.00000. Input {"nums": [4, 2, 1, 3], "k": 2}; Output 3.00000

Constraints

n == nums.length 1 <= k <= n <= 10^5 -10^4 <= nums[i] <= 10^4

Practice Maximum Average Subarray I free on ExecCode. Browse DSA problems, topic map, and placement guides.