Question bank › Sliding Window
Dsa Sliding Window Easy

Maximum Sum of Consecutive Elements

Given an array of integers 'arr' and an integer 'k', write a function to return the maximum sum of any contiguous subarray of size 'k'. ### Input Format: - The first line contains integers n, k (1 <= n <= 1000, 1 <= k <= n). - The second line contains n space-separated integers representing the elements of 'arr'. ### Output Format: - Output the maximum sum of a contiguous subarray of size k. ### Example: Input: 6 3 1 2 3 4 5 6 Output: 15 ### Explanation: The subarray [4,5,6] has the maximum sum of 15.

Key concepts

sliding_windowarrayprefix_sum

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
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.