easySliding WindowPattern: Fixed Sliding Window
Maximum Average Subsequence Solution
Problem Statement
Given an array of integers `values` and an integer `windowSize`, find the maximum average value over any subsequence of `windowSize` consecutive elements. Return the maximum average multiplied by 100000, rounded down to the nearest integer.
Examples
Example 1:
Input:{"nums":[1,12,-5,-6,50,3],"k":4}
Output:10602
Explanation: Maximum average daily intake is calculated over any K-day window.
Constraints
- 1 <= k <= n <= 10^5
- -10^4 <= arr[i] <= 10^4
Time: O(N) Space: O(1)
Fixed size sliding window. Calculate initial window sum. Slide one by one, update max sum. Finally return max_sum * 100000 / k. Time O(N), Space O(1).
Run, Test & Submit Code
Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.
Solve on Interactive WorkspaceTested Solutions
No solution code is currently loaded.
Complete this code in the workspace editor.
