Your question is Sliding Window Max Subarray Sum. 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.
Spotify analyzes contiguous windows of playlist metrics, such as track engagement scores. Given an integer array nums and a window size k, return the maximum sum among all contiguous subarrays containing exactly k elements.
Implement max_subarray_sum(nums, k).
nums, a non-empty list of integers, and k, an integer window size.k.k elements.Use a fixed-size sliding window rather than recomputing every window from scratch.
def max_subarray_sum(nums, k):