Basic example
Input
nums = [1, 2, 3, 4, 5], k = 7
Output
3
The longest subarray with sum <= 7 is [1,2,3] with length 3 (sum=6).
Full lesson preview
Given a list of non-negative integers and a threshold k, find the maximum length of a contiguous subarray whose sum is <= k.
Problem statement
Task
Examples
Input
nums = [1, 2, 3, 4, 5], k = 7
Output
3
The longest subarray with sum <= 7 is [1,2,3] with length 3 (sum=6).
Input format
Output format
Constraints
Samples
Input
nums = [2, 1, 1, 1, 5, 1, 1], k = 4
Output
3
One longest subarray is [1,1,1] with sum 3 and length 3.