Question bank › Arrays
Dsa Arrays Easy

Maximal Subarray of Length K

You are given an array of integers and an integer k. Find the maximal sum of any contiguous subarray of length k. Input format: - 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 (|a[i]| <= 1000), the elements of the array. - The third line contains an integer k (1 <= k <= n). Output format: - Output a single integer denoting the maximal sum of the subarray of length k. Example: Input: 5 2 1 5 1 3 3 Output: 9

Key concepts

arrayssliding-window

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.