Search⌘ K
AI Features

Minimum Size Subarray Sum

Explore how to apply the sliding window technique to identify the smallest contiguous subarray with a sum greater than or equal to a given target. Learn to efficiently solve this problem with positive integers, practice implementing your solution, and understand the approach for related subarray challenges.

Statement

Given an array of positive integers, nums, and a positive integer, target, find the minimum length of a contiguous subarray whose sum is greater than or equal to the target. If no such subarray is found, return 0.

Constraints:

  • 11 \leq target \leq 10410^4
  • 11 \leq nums.length \leq 10310^3
  • 11 \leq nums[i] \leq 10310^3

Examples

canvasAnimation-image
1 / 3

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Minimum Size Subarray Sum

1.

What is the output if the following values are given as input?

nums = [1, 2, 7, 1, 8]

target = 9

A.

3

B.

2

C.

5

D.

1


1 / 3

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5
6

Try it yourself

Implement your solution in the following coding playground:

C++
usercode > main.cpp
#include <climits>
int MinSubArrayLen(int target, vector<int>& nums){
// Replace this placeholder return statement with your code
return -1;
}
Minimum Size Subarray Sum