Maximum Ascending Subarray Sum

Given an array of positive integers `nums`, return the **maximum** possible sum of an **ascending** subarray in `nums`. A subarray is ascending if each element is strictly greater than the element before it. Note that a subarray of size 1 is ascending.

30:00

Maximum Ascending Subarray Sum
easy
Free written solution
Topics
Companies

Given an array of positive integers nums, return the maximum possible sum of an ascending subarray in nums. A subarray is ascending if each element is strictly greater than the element before it. Note that a subarray of size 1 is ascending.

Example 1:
Input: {"nums":[10,20,30,5,10,50]}
Output: 65
Constraints:
  • 1≤nums.length≤1001 \leq \text{nums.length} \leq 100

  • 1≤nums[i]≤1001 \leq \text{nums}[i] \leq 100

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[10,20,30,5,10,50]}

Find the climbing runs: stretches where every bar is taller than the one before. All values are positive, so a whole run always beats any part of it.

bars = nums; a red cut marks where the climb stops (nums[i] ≤ nums[i-1])

10203051050best 10

cur

10

best

10

best run: [10]

best = 10

Variables
VariableValue
n6
DepthFunction Call
Stack empty
0/13