cswork / libraryOpen practice workspace

Coding questions · DoorDash

Find Maximum Window Sum

This question evaluates array manipulation, algorithmic efficiency, and familiarity with the sliding-window technique for computing metrics over fixed-length contiguous subarrays.

Given an integer array nums and an integer k, write code to find the maximum sum of any contiguous subarray of length exactly k. Assume 1 <= k <= len(nums), values may be negative, and the expected solution should run in O(n) time using a sliding-window approach.

Maximum Fixed-Window Sum

Examples

Example 1

Input: ([1,2,3,4,5], 2)
Output: 9

Explanation: Best length-two window.

Example 2

Input: ([-5,-2,-3], 2)
Output: -5

Explanation: All negative.

Hints

  1. Choose a representation that makes the core operation simple.
  2. Handle empty and boundary inputs before the main algorithm.