Dsa
Sliding Window
Medium
Max Sum Subarray of K Length
You are given an array of integers and an integer k. Your task is to find the maximum sum of any contiguous subarray of size k. If k is greater than the length of the array, return 0.
Input:
- The first line contains two integers, n (1 <= n <= 100,000) and k (1 <= k <= n).
- The second line contains n integers representing the array elements (each between -10^4 and 10^4).
Output:
- Print the maximum sum of the window of size k.
Example:
Input:
5 2
1 2 3 4 5
Output:
9
Key concepts
sliding_windowarraysubarray
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