The Maximum Subarray

  • + 0 comments

    Pythonic 2 lines:

    def maxSubarray(arr):
        p = [n for n in arr if n > 0]
        return [max(accumulate(arr, lambda s, n: 0 if s+n < 0 else s+n, initial=0)), sum(p)] if p else [max(arr)] * 2