Show problems as
Classic problem #1800EasyArray

Maximum Ascending Subarray Sum

Real-world version: The Heaviest Rising Run
Tracked in this browser only
Read Maximum Ascending Subarray Sum on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A strip of positive readings reads readings. A run of neighbouring readings rises when each of its readings is strictly larger than the one before it; a run of a single reading rises by default.

Return the largest total any rising run adds up to.

Examples

Example 1

Input
readings = [1, 2, 3, 1]
Output
6

The first three readings rise and add to six. The last reading breaks the run and stands alone at one.

Example 2

Input
readings = [7, 7, 7]
Output
7

No reading is strictly larger than the one before, so every rising run holds a single reading.

Example 3

Input
readings = [9, 4, 5]
Output
9

The 9 stands alone at nine, while the rising run 4 then 5 adds only to nine as well, so nine is the answer either way.

Constraints

  • 1 <= readings.length <= 100
  • 1 <= readings[i] <= 100

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def max_ascending_sum(readings: list[int]) -> int:
Java
public int maxAscendingSum(int[] readings)