Minimum Size Subarray Sum
Medium Sliding Window
nums is a list of positive whole numbers, and target is a positive whole number.
A subarray is a run of one or more numbers that sit next to each other in nums. Find the shortest subarray whose numbers add up to target or more.
Return the length of that subarray, or 0 if there is none: when even the whole list adds up to less than target.
Example 1
2 + 6 + 3 = 11 reaches the target with three numbers next to each other. No two neighbours add up to 10 or more (the most is 6 + 3 = 9), so nothing shorter works.
Example 2
All four numbers add up to 17, less than 20, so no subarray reaches the target.
Example 3
Constraints
1 ≤ nums.length ≤ 2 × 10⁵1 ≤ nums[i] ≤ 50001 ≤ target ≤ 10⁹
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundWatch the explanation
More Sliding Window
- Longest Substring Without Repeating CharactersAI round · Medium
- Sliding Window MaximumAI round · Hard
- Minimum Window SubstringAI round · Hard
- Longest Repeating Character ReplacementAI round · Medium
- Longest Substring with At Most K Distinct CharactersMedium