Dsa
Sliding Window
Easy
Max Sum of Subarray Length K
Given an array of integers and an integer K, find the maximum sum of any contiguous subarray of length K. You must read the input as a single line separated by spaces, where the first integer is the length of the array followed by the elements of the array and the integer K. If K is greater than the length of the array, return -1.
Example:
Input:
5 2 1 5 1 3 2
3
Output:
9
Key concepts
sliding_windowsubarraysum
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now