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
Maximum Ascending Subarray SumInput:10203051050Ascending Sequences:[10,20,30] = 60[5,10,50] = 65Maximum:65Find the ascending subarray with the largest sum
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
Asked in
Amazon 15 Google 8
24.1K Views
Medium Frequency
~8 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen