All problems
1085EasyArray

The Heaviest Rising Run

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1800Maximum Ascending Subarray Sum

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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