Question bank › Sliding Window
Dsa Sliding Window Medium

Maximal Sum Subarray

Given an integer array `nums` and an integer `k`, return the maximum sum of elements in 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 space-separated integers, representing the elements of the array `nums` (-1000 ≤ nums[i] ≤ 1000). - The third line contains an integer k (1 ≤ k ≤ n), the size of the subarray. Output: - An integer representing the maximum sum of the subarray of size `k`. Example: Input: 5 1 2 3 4 5 3 Output: 12

Key concepts

sliding_windowarrayssum

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.