I knew sliding window immediately, got the O(n) logic down pretty fast.
Use a sliding window of size k to compute the sum of each contiguous k-day period in O(n) time. Track the maximum sum and the earliest starting index (1-based) that achieves it. Return the result as a list containing that index.
Pro tip: Mention that you handle edge cases like k > array length or empty array, and clarify that ties are broken by choosing the earliest start day. Also, note that the result should be wrapped in a list as specified.
Restate the problem: find the contiguous k-day period with the maximum sum, return the 1-based start day as a list, and break ties by earliest start. Ask clarifying questions about input size, possible negative values, and edge cases.
Explain that a sliding window of size k allows computing each window sum in O(1) by adding the new element and subtracting the old one, achieving O(n) time and O(1) extra space.
Compute the sum of the first k elements, set it as the current maximum, and record start index 1. Then slide the window from index k to n-1, updating the sum and checking if the new sum exceeds the current maximum (strictly greater to keep earliest tie).
If k > n or n == 0, return an empty list or handle as appropriate. After the loop, return [best_start] where best_start is the 1-based index of the maximum sum window.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.