Minimum Subarray Sum

Sliding Window Array Two Pointers

Problem Description

In celebration of International Volunteer Day on December 5, imagine you're organizing a volunteer event. Every volunteer contributes a certain satisfaction score, represented as an array of positive integers. Your task is to determine the smallest contiguous group of volunteers whose combined satisfaction score is greater than or equal to a given target value. This problem can be effectively solved using the sliding window technique.

Task

Write a function that receives an array of positive integers and a target sum, and returns the length of the smallest contiguous subarray whose sum is at least the target. If no such subarray exists, return 0.

Example

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

Output: 2

Explanation: The subarray [4, 3] has a sum of 7 and is the shortest such subarray.

Function Signature

Complete the function with the provided signature in your chosen programming language.