Show problems as
Classic problem #674EasyArray

Longest Continuous Increasing Subsequence

Real-world version: Longest Rising Run of Gauge Readings
Tracked in this browser only
Read Longest Continuous Increasing Subsequence on LeetCode(opens in a new tab)

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

Learn the pattern firstSliding Window · Arrays, animated step by step

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.

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