Question bank › Sliding Window
Dsa Sliding Window Medium

Min Size Subarray Sum

Given an array of positive integers `nums` and a positive integer `target`, return the minimal length of a contiguous subarray of which the sum is greater than or equal to `target`. If there is no such subarray, return 0. Input Format: - The first line contains an integer n (1 <= n <= 10^5). - The second line contains n space-separated integers representing the elements of the array where (1 <= nums[i] <= 10^4). - The third line contains an integer target (1 <= target <= 10^6). Output Format: - Print the minimal length of a subarray whose sum is at least `target`. Example: Input: 5 2 3 1 2 4 7 Output: 2

Key concepts

sliding_windowprefix_sumarrays

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.