Created
April 17, 2019 11:05
-
-
Save 4skinSkywalker/d7f9f940bf89c0fa9fe17c7a277bb481 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 maxKAdjacentSum(array, k) { | |
| if (array.length < k) | |
| return null | |
| let runningSum = 0 | |
| for (let i = 0; i < k; i++) | |
| runningSum += array[i] | |
| let highestSum = runningSum | |
| for (let j = 0; j < array.length - k; j++) { | |
| runningSum += array[j + k] - array[j] | |
| highestSum = Math.max(highestSum, runningSum) | |
| } | |
| return highestSum | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment