728x90
function maxLength(a, k) {
let start = 0;
let sum = 0;
let maxLen = 0;
for(let end = 0; end < a.length; end++) {
sum += a[end];
while(sum > k) {
sum -= a[start];
start++;
}
maxLen = Math.max(maxLen, end - start + 1);
}
return maxLen;
}
728x90