Problems / Shortest Subarray With Sum ≥ Target
Medium

Shortest Subarray With Sum ≥ Target

Medium 103 submissions 25 coins +100 XP
Binary Search Prefix Sum Sliding Window
Problem Description
All values in `nums` are positive. Return the length of the shortest contiguous subarray whose sum is **at least** `target`, or `0` if no such subarray exists. **Example 1:** ``` Input: target = 7, nums = [2, 3, 1, 2, 4, 3] Output: 2 ``` **Example 2:** ``` Input: target = 4, nums = [1, 4, 4] Output: 1 ``` **Example 3:** ``` Input: target = 11, nums = [1, 1, 1, 1, 1] Output: 0 ```
Constraints
- `1 <= target <= 10^9` - `1 <= nums.length <= 10^5` - `1 <= nums[i] <= 10^4`

Need help?

Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.

Video Call Whiteboard Live Coding Screen Share