one-line-wonders icon indicating copy to clipboard operation
one-line-wonders copied to clipboard

Largest sum of consecutive numbers in an array

Open lelchan opened this issue 6 years ago • 3 comments

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.

lelchan avatar Oct 29 '18 03:10 lelchan

Well, I think I got it for Python.

gsafcik avatar Oct 31 '18 05:10 gsafcik

Solved this issue in pull request https://github.com/wzhouwzhou/one-line-wonders/pull/410

yashagarwal1999 avatar Oct 21 '19 04:10 yashagarwal1999

Solved this issue in pull request https://github.com/wzhouwzhou/one-line-wonders/pull/412

yashagarwal1999 avatar Oct 22 '19 04:10 yashagarwal1999