You are viewing a single comment's thread. Return to all 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
Seems like cookies are disabled on this browser, please enable them to open this website
The Maximum Subarray
You are viewing a single comment's thread. Return to all comments →
Pythonic 2 lines: