Fundamentals/Subarray Sum Longest
← PrevNext →
Given an array nums of non-negative integers and an integer target, return the length of the longest contiguous subarray whose sum is less than or equal to target.
Input
nums: array of non-negative integers
target: the maximum allowed sum
Output
The length of the longest qualifying subarray (0 if none exists).
Examples
Example 1
Inputnums = [1, 6, 3, 1, 2, 4, 5], target = 10
Output4
Example 2
Inputnums = [10, 10, 10], target = 5
Output0
Constraints
0 <= nums.length <= 10^5.
0 <= nums[i].
0 <= target.