Back to course home
0% completed
Vote For New Content
Minimum Size Subarray Sum (medium)
Problem Statement
Given a nums
array containing positive integers and a positive integer target
, return the minimum length of a
subarray
having the sum of elements greater
than or equal
to target
. If there is no such subarray, return 0 instead.
Examples
Example 1:
- Input:
target = 15
,nums = [1, 2, 3, 4, 5, 6, 7, 8]
- Expected Output:
2
- Justification: The subarray
[7, 8]
has a sum of15
, which is equal totarget
and is the smallest possible subarray.
Example 2:
- Input:
target = 11
,nums = [2, 1, 5, 2, 8]
- Expected Output:
3
- Justification: The subarray
[5, 2, 8]
has a sum of15
, which meets thetarget
and is the smallest possible subarray.
Example 3:
- Input:
target = 8
,nums = [2, 1, 5, 2, 3]
- Expected Output:
3
- Justification: The subarray
[5, 2, 3]
has a sum of10
, which meets thetarget
and is the smallest possible subarray.
Constraints:
- 1 <= target <= 10<sup>9</sup>
- 1 <= nums.length <= 10<sup>5</sup>
- 1 <= nums[i] <= 10<sup>4</sup>
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible