ORIGINAL CODING QUESTION
Fixed-window peak workload
Return the maximum sum among contiguous windows of exactly k values. Negative sums remain negative.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n signed values, then k.
Constraints
1 ≤ n ≤ 200; -100 ≤ value ≤ 100; 1 ≤ k ≤ n.
Example 1
Input
5 2 -1 3 4 -2 2
Output
7
The window 3,4 sums to 7.
Example 2
Input
3 -3 -2 -1 2
Output
-3
The best length-two sum is -3.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Keep the window length fixed.
Hint 2
Add the entering value and subtract the leaving value.
Hint 3
Initialize from an actual window rather than zero.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →