Dsa
Sliding Window
Easy
Maximum Sum in Sliding Window
Given an array of integers and a positive integer k, find the maximum sum of any contiguous subarray of size k.
Input:
The first line contains an integer n (1 ≤ n ≤ 10^5), the number of elements in the array.
The second line contains n integers, which are the elements of the array.
The third line contains an integer k (1 ≤ k ≤ n).
Output:
An integer representing the maximum sum of a contiguous subarray of size k.
Example:
Input:
5
1 2 3 4 5
3
Output:
12
(Explanation: The maximum sum is 3 + 4 + 5 = 12.)
Key concepts
sliding_windowarrayssummation
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