Maximum Ascending Subarray Sum - Problem
Given an array of positive integers nums, return the maximum possible sum of a strictly ascending subarray in nums.
A subarray is defined as a contiguous sequence of numbers in an array.
An ascending subarray is one where each element is strictly greater than the previous element: nums[i] < nums[i+1] < nums[i+2] ...
Input & Output
Example 1 — Basic Ascending Sequence
$
Input:
nums = [10,20,30,5,10,50]
›
Output:
65
💡 Note:
Two ascending subarrays: [10,20,30] with sum 60 and [5,10,50] with sum 65. Maximum is 65.
Example 2 — Single Elements
$
Input:
nums = [10,20,30,40]
›
Output:
100
💡 Note:
Entire array is ascending: 10 < 20 < 30 < 40, sum = 10+20+30+40 = 100.
Example 3 — Decreasing Array
$
Input:
nums = [5,4,3,2,1]
›
Output:
5
💡 Note:
No ascending subarray exists except single elements. Maximum single element is 5.
Constraints
- 1 ≤ nums.length ≤ 100
- 1 ≤ nums[i] ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Array with mixed ascending/descending sequences
2
Identify Sequences
Find all strictly ascending subarrays
3
Calculate Maximum
Return the highest sum among all sequences
Key Takeaway
🎯 Key Insight: Track current ascending sum, reset when sequence breaks, keep maximum
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code