Basic example
Input
arr = [2, 1, 5, 1, 3, 2], K = 3
Output
9
Subarray [5,1,3] has the maximum sum 9.
Full lesson preview
Compute the maximum sum among all contiguous subarrays of fixed size K using a sliding window.
Problem statement
Task
Examples
Input
arr = [2, 1, 5, 1, 3, 2], K = 3
Output
9
Subarray [5,1,3] has the maximum sum 9.
Input format
Output format
Constraints
Samples
Input
arr = [2, 3, 4, 1, 5], K = 2
Output
7
Subarray [3,4] has sum 7.