Your question is Sliding Window Max Subarray. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Wise. Energy analyzes consecutive energy readings to identify the highest-consumption period of a fixed duration. Given an integer array and a window size k, return the maximum sum of any contiguous subarray containing exactly k elements.
Implement max_window_sum(nums, k).
nums, a non-empty list of integers representing energy readings, and k, an integer window size.k.1 <= k <= len(nums).The window must contain exactly k consecutive readings. Do not sort or rearrange the input.
def max_window_sum(nums, k):