Maximum Ascending Subarray Sum
Real-world version: The Heaviest Rising RunThe 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.
def max_ascending_sum(readings: list[int]) -> int:public int maxAscendingSum(int[] readings)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's