Question bank › Sliding Window
Dsa Sliding Window Medium

Maximum Sum of K Consecutive Elements

Given an array of integers `arr` and an integer k, calculate the maximum sum of any consecutive subarray of size k. If the size of the array is less than k, return 0. Input Format: - The first line contains two integers n (1 <= n <= 10^5) and k (1 <= k <= n). - The second line contains n space-separated integers representing the elements of the array. Output Format: - Print the maximum sum of any k consecutive elements. Example: Input: 5 3 1 2 3 4 5 Output: 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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.