Simple python solution, ~10 lines, top 99% time & mem. Comments before every line.
Intuition\n\nA good way to build intuition for this problem is by first solving its simpler version: Maximum Subarray (problem 53 in LeetCode). This will provid
# Intuition\n\nA good way to build intuition for this problem is by first solving its simpler version: Maximum Subarray (problem 53 in LeetCode). This will provide an understanding of the basic update set.\n\n# Approach\n\nWhile the current num is non-negative, we simply add it. Otherwise, we required more elaborate update. \n\nThe main idea is that we keep two sums: one that doesn\'t allow skipping, and one that does. By updating the \'noskip\' sum later, it points to the sum that was achieved on the previous step. Thus, if we use it, it is as if we skipped the current num. \n\nLast note is that we need to \'reset\' the sums in case they are negative before they are used. The reason is that A + B < B for any negative A. \n\n# Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution:\n    def maximumSum(self, nums: List[int]) -> int:\n        # summation with possible skips\n        skip = nums[0]\n        # summation without skips\n        noskip = nums[0]\n        # holder for maximal value\n        maxv = nums[0]\n        for num in nums[1:]:\n            # reset skip if negative\n            if skip < 0: skip = 0\n            # if num is positive just add. otherwise take the maximum between adding it,\n            # and skipping it - represented by noskip that currently is on previous position\n            skip = skip + num if num >= 0 else max(skip + num, noskip) \n            # reset noskip if negative\n            if noskip < 0: noskip = 0\n            # always add\n            noskip += num                \n            # track maximum\n            maxv = max(maxv, noskip, skip)\n\n        return maxv            \n    \n```
['Python3']