Dsa
Sliding Window
Easy
Max Sum Subarray of Size K
Given an array of integers and an integer K, find the maximum sum of any contiguous subarray of size K. You must perform this in O(n) time complexity.
Input:
- The first line contains an integer N (1 <= N <= 10^5) - the number of elements in the array.
- The second line contains N space-separated integers representing the array elements.
- The third line contains the integer K (1 <= K <= N).
Output:
- Output a single integer representing the maximum sum of any contiguous subarray of size K.
Example:
Input:
5
1 2 3 4 5
3
Output:
12
Key concepts
sliding_windowarraysum
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