Search⌘ K

Minimum Size Subarray Sum

Explore how to find the length of the smallest contiguous subarray in an array where the sum is at least a given target. This lesson teaches you to use a two-pointer approach to achieve an optimal linear time solution, deepening your understanding of array algorithms and subarray problems.

Statement

Given an array of positive integers, nums, along with a positive integer, target. Find the length of the shortest contiguous subarray whose sum is greater than or equal to the target. If there is no such subarray, return 0 instead.

Example

Sample input

target = 7
nums = [2,3,1,2,4,3]

Expected output

2

Try it yourself

#include <climits>
#include <iostream>
#include <vector>
using namespace std;
int MinSubArrayLen(int s, vector<int> &nums) {
// TODO: Write - Your - Code
return -1;
}

Solution

In this ...