Skip to content

Instantly share code, notes, and snippets.

@sbrin
Last active August 9, 2020 09:58
Show Gist options
  • Save sbrin/ad3a39f8079cffdc51b15c57c89e6407 to your computer and use it in GitHub Desktop.
Save sbrin/ad3a39f8079cffdc51b15c57c89e6407 to your computer and use it in GitHub Desktop.
function maxLength(a, k) {
let result = 0;
for (let i = 0; i < a.length; i++) {
let arr = [];
if (a[i] <= k) {
let arraySum = 0;
for (let j = i; j < a.length; j++) {
if (arraySum + a[j] <= k) {
arraySum += a[j];
arr.push(a[j]);
} else {
break;
}
}
}
if (arr.length > 0) {
if (arr.length > result) {
result = arr.length;
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment