← 返回 doordash 的题目列表Max Sum Sliding Window and Return Start Days (1-based)
类型:online_judge
Problem (Python)
Given an integer array nums of length n and a window size k (1 <= k <= n), compute the sum of every contiguous subarray of length k.
Return all window start positions ("start days") whose window sum equals the maximum window sum. The start positions must be 1-based indices.
If multiple windows tie for the maximum sum, return all their start positions in increasing order.
Input
nums: integer array of length n
k: window size
Output
A list of integers representing all 1-based start indices achieving the maximum sum.
Constraints (reasonable for interview)
1 <= n <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
1 <= k <= n
Examples
Input: nums = [1, 2, 3, 1, 2], k = 2
Window sums: 3 (start 1), 5 (start 2), 4 (start 3), 3 (start 4)
Max is 5 at start 2
Output: [2]
Input: nums = [5, 1, 5, 1], k = 2
Window sums: 6 (start 1), 6 (start 2), 6 (start 3)
Output: [1, 2, 3]
Example
Input
nums=[1,2,3,1,2], k=2
Output
[2]