There are three kinds of actuaries: those who can count, and those who can't.
I'm not sure where your headed with this. Even the max subsequence can have negative numbers in it and negative numbers still need to be added into the sum.Junilu Lacar wrote:I would also look into something like findFirst() or findAny() to see if there are negative numbers in a sequence/subsequence. Then use the IntStream.sum() function.
Carey Brown wrote:I'm not sure where your headed with this. Even the max subsequence can have negative numbers in it and negative numbers still need to be added into the sum.
Piet Souris wrote:Look for "largest sum of subarrays" on the internet, where you find Kadane's O(N) solution.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:Don't try this with brute force. There are N^2 (or so) subsets, so that would take a long time, even though you can apply many shortcuts.
Consider Paul's rocket mass heater. |