JavaRanch-FAQ HowToAskQuestionsOnJavaRanch UseCodeTags DontWriteLongLines ItDoesntWorkIsUseLess FormatCode JavaIndenter SSCCE API-11 JLS JavaLanguageSpecification MainIsAPain KeyboardUtility
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.
JavaRanch-FAQ HowToAskQuestionsOnJavaRanch UseCodeTags DontWriteLongLines ItDoesntWorkIsUseLess FormatCode JavaIndenter SSCCE API-11 JLS JavaLanguageSpecification MainIsAPain KeyboardUtility
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.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |