Question bank › Sliding Window
Dsa Sliding Window Medium

Maximum Sum of Subarray

You are given an array of integers `nums` and an integer `k`. Your goal is to find the maximum sum of any contiguous subarray of size `k`. Implement a function that reads from standard input and prints the maximum sum to standard output. ### Input Format: - The first line contains the integer `n` (1 <= n <= 10^5). - The second line contains integers `nums` (array of n integers, -10^4 <= nums[i] <= 10^4). - The third line contains the integer `k` (1 <= k <= n). ### Output Format: - An integer representing the maximum sum of any contiguous subarray of size `k`. ### Example: Input: 5 1 2 3 4 5 3 Output: 12 In the example, the maximum sum of any contiguous subarray of size 3 is 12 (from the subarray [3, 4, 5]).

Key concepts

sliding_windowarrays

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.