Trains the technique from
LeetCode 334Increasing Triplet SubsequenceThis 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 reading per hour into a log. readings[t] is the water level at hour t, measured against the datum mark, so it may be negative when the level sits below the mark.
The flood office wants to know whether the log contains a rising trio: three hours i < j < k with readings[i] < readings[j] < readings[k]. The three hours do not have to be next to each other, but they must appear in that order in the log, and each step must be a strict increase.
Return true if the log contains a rising trio and false otherwise. Your solution should run in O(n) time and use O(1) extra space.
Example 1
Hours 2, 3 and 5 hold -2, 5 and 7. Those hours are in increasing order and -2 < 5 < 7, so the log has a rising trio.
Example 2
No reading is ever followed later by a larger one, so not even a rising pair exists, let alone a trio.
Example 3
Hours 1, 3 and 4 hold 1, 2 and 8, and 1 < 2 < 8.
Example 4
The rising pairs available are (4, 5) and (1, 2), and neither has a third larger reading after it, so there is no trio.
Example 5
Every reading equals the next, and equal readings are not a strict increase.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def has_rising_trio(readings: list[int]) -> bool:public boolean hasRisingTrio(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.