one-line-wonders
one-line-wonders copied to clipboard
Largest sum of consecutive numbers in an array
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.
Well, I think I got it for Python.
Solved this issue in pull request https://github.com/wzhouwzhou/one-line-wonders/pull/410
Solved this issue in pull request https://github.com/wzhouwzhou/one-line-wonders/pull/412