Today’s problem

https://leetcode.com/problems/maximum-ascending-subarray-sum/

Intuition

Same as the problem yesterday, the only difference is changing count to sum.

Approach

Same as the problem yesterday, the only difference is changing count to sum.

Complexity

  • Time complexity: $O(N)$, N is the length of the array.

  • Space complexity: $O(1)$

Code

class Solution:
    def maxAscendingSum(self, nums: List[int]) -> int:
        ans, tmp, pre = nums[0], nums[0], nums[0]
        for num in nums[1::]:
            if num > pre:
                tmp += num
            else:
                ans = max(ans, tmp)
                tmp = num
            
            pre = num
        
        return max(tmp, ans)

image.png