Number of Longest Increasing Subsequence
Real-world version: Counting The Longest Rising Gauge RunsThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def longest_rise_count(marks: list[int]) -> int:public int longestRiseCount(int[] marks)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 14 test cases: 14 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
More on the same topics
- Longest Increasing Subsequence IIReal-world version: Longest Rising Run Under a Step CapHard
- Longest Increasing SubsequenceReal-world version: Longest Rising Anomaly PickMedium
- Queue Reconstruction by HeightReal-world version: Rebuild the Photo LineMedium
- Block Placement QueriesReal-world version: Rail Panel Fit OrdersHard