Leetcode 1927 Solution
This article provides solution to leetcode question 1927 (maximum-ascending-subarray-sum)
Access this page by simply typing in "lcs 1927" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/maximum-ascending-subarray-sum
Solution
class Solution:
def maxAscendingSum(self, nums: List[int]) -> int:
ans = 0
curr_sum = 0
last_val = -1
for num in nums:
if num > last_val:
curr_sum += num
else:
curr_sum = num
ans = max(curr_sum, ans)
last_val = num
return ans