Maximum Subarray Sum

  • + 0 comments

    This link, which is also posted further down in the discussion, explains it: StackOverflow Explanation

    Given a sum array where Si = the modulus sum of A0 to Ai, a subarray within A0-Ai will only produce a larger mod sum if Sj (j = start of the subarray) is greater than Si and as close to Si as possible.

    Knowing this you can build a binary tree, or binary search a sorted array, to discover if a sub array results in a larger mod sum than the mod sum at Si. You don't have to calulate the mod sum of every possible subarray.