Maximum Sum of Subarray of Size K

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

Input Format

nums = array of integers, k = window size

Output Format

Maximum sum of any subarray of length k

Constraints

  • 1 <= k <= nums.length <= 10^5; -10^4 <= nums[i] <= 10^4

Examples

Example 1:

Input:

nums = [2,1,5,1,3,2]
k = 3

Output:

9

Explanation:

Subarray [5,1,3] has the maximum sum 9.

Loading...
Maximum Sum of Subarray of Size K - Arrays