Dsa
Sliding Window
Warm-up
Max Sum Subarray of Fixed Size
Given an array of integers and a fixed size k, find the maximum sum of any contiguous subarray of size k.
Input format:
- The first line contains an integer n (1 <= n <= 10^5), the size of the array.
- The second line contains n space-separated integers, the elements of the array (each element ai (−10^4 <= ai <= 10^4)).
- The third line contains an integer k (1 <= k <= n).
Output format:
- Print a single integer, the maximum sum of any contiguous subarray of size k.
Example:
Input:
5
1 2 3 4 5
3
Output:
12
Key concepts
sliding_windowarrayssums
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