Longest Continuous Increasing Subsequence
Real-world version: Longest Rising Run of Gauge ReadingsThe statement here is our own: the same inputs, outputs and technique.
A river gauge writes one water level per hour into readings, in the order the levels were taken. Levels are whole numbers and may be negative when the water is below the gauge's mark.
A rising run is a block of neighbouring entries readings[i] through readings[j] in which every entry is strictly greater than the entry just before it inside the block. A block of one entry counts as a rising run, and two equal entries side by side cannot be in the same run.
Return the number of entries in the longest rising run of readings.
Examples
Example 1
- Input
- readings = [4, 9, 11, 3, 6, 8, 20]
- Output
- 4
The block `3, 6, 8, 20` at the end holds four entries and each is strictly above the one before it, so it is a rising run of four.
Example 2
- Input
- readings = [15, 12, 9, 6]
- Output
- 1
Every entry is below the one before it, so no block of two entries rises and each single entry is a run of one.
Example 3
- Input
- readings = [9, 4, 6, 6, 7, 8, 9]
- Output
- 4
The two equal entries of `6` cannot share a run, so the run ending at the last entry starts at the second `6` and holds `6, 7, 8, 9`.
Constraints
- 1 <= readings.length <= 10^4
- -10^9 <= readings[i] <= 10^9
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 longest_rising_run(readings: list[int]) -> int:public int longestRisingRun(int[] readings)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 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