Last active
August 9, 2020 09:58
-
-
Save sbrin/ad3a39f8079cffdc51b15c57c89e6407 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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