All problems
0464MediumArrayDynamic ProgrammingBinary Indexed TreeSegment TreeLongest Increasing Subsequence

Counting The Longest Rising Gauge Runs

Tracked in this browser only
Write code

Trains the technique from

LeetCode 673Number of Longest 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 reports its level against a datum, so a reading may be negative. marks holds one reading per hour, earliest hour first.

A rising run is a pick of one or more readings, kept in the order the hours were logged, in which each reading picked is strictly above the one picked before it. The hours picked need not be consecutive. Two runs are different when they pick different hours, even if the readings they pick happen to match.

Return how many rising runs are as long as the longest rising run in the log.

Examples

Example 1

Input
marks = [-14, 62, 5, 90, 41]
Output
3

The longest rising runs pick three hours: -14, 62, 90 and -14, 5, 90 and -14, 5, 41.

Example 2

Input
marks = [77, 77, 77]
Output
3

No reading is strictly above another, so the longest run picks a single hour, and each of the three hours gives one such run.

Example 3

Input
marks = [-8, -20, 46, -3, 46]
Output
2

The longest runs pick three hours: -20 then -3 then the later 46, and -8 then -3 then that same 46.

Constraints

  • 1 <= marks.length <= 2000
  • -10^6 <= marks[i] <= 10^6
  • The answer is guaranteed to fit in a signed 32-bit integer.

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_rise_count(marks: list[int]) -> int:
Java
public int longestRiseCount(int[] marks)
September 7
Apply