Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Outline

Check Out My YouTube Channel

Algorithm Challenge Available At CodeFights

Given array of integers, find the maximal possible sum of some of its k consecutive elements.

Example

For inputArray = [2, 3, 5, 1, 6] and k = 2, the output should be arrayMaxConsecutiveSum(inputArray, k) = 8. All possible sums of 2 consecutive elements are:

  • 2 + 3 = 5;
  • 3 + 5 = 8;
  • 5 + 1 = 6;
  • 1 + 6 = 7.

Thus, the answer is 8

Input/Output

  • [execution time limit] 4 seconds (js)
  • [input] array.integer inputArray Array of positive integers.

Guaranteed constraints:

3 ≤ inputArray.length ≤ 105,

1 ≤ inputArray[i] ≤ 1000.

  • [input] integer k

An integer (not greater than the length of inputArray).

Guaranteed constraints: 1 ≤ k ≤ inputArray.length.

  • [output] integer

The maximal possible sum.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.