BackeasySliding Window

Maximum Sum Subarray of Size K Solution

Problem Statement

Given an array of positive integers nums and an integer k, find the maximum sum of any contiguous subarray of size k.

Example 1
Input
4 2 100 200 300 400
Output
700

Explanation: Subarray [300, 400] has the maximum sum of 700.

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= k <= nums.length
Live Compiler
Sign InSign Up
Loading...
Test Cases & Output
Click "Run" to execute