Trains the technique from
LeetCode 3105Longest Strictly Increasing or Strictly Decreasing SubarrayThis 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 strip of readings reads readings.
Return the length of the longest run of neighbouring readings that either climbs strictly all the way or falls strictly all the way. A run of a single reading counts as both.
Example 1
The first three readings climb strictly, which is a run of three. The fall at the end reaches only two.
Example 2
The two readings are equal, so neither climbs nor falls, leaving runs of one.
Example 3
The strip falls for three readings and then climbs for four, so the climbing run is the longer.
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 longest_monotonic_subarray(readings: list[int]) -> int:public int longestMonotonicSubarray(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.