Largest sum of consecutive numbers in an array #162
Labels
enhancement
New feature or request
hacktoberfest-accepted
Hacktoberfest!
help wanted
Extra attention is needed
question
Further information is requested
Projects
You are given an array with n distinct integers. Design an algorithm that returns two integers i and j, where i <= j, for which the sum of the elements at positions i, (i+1), ....(j-1), j is maximum.
eg. [1, 4, -2, 6, -5, 3] would return 0 and 3, for i and j respectively. The largest sum of consecutive numbers we can get from this array is 9, 1 + 4 - 2 + 6 = 9.
I haven't seen any one line wonders of this yet, but it can be done in O(n) time when solved normally.
The text was updated successfully, but these errors were encountered: