All problems
0673EasyArray

Longest Rising Run of Gauge Readings

Tracked in this browser only
Write code

Trains the technique from

LeetCode 674Longest Continuous Increasing Subsequence

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

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