Trains the technique from
LeetCode 414Third Maximum NumberThis 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 weather post logs one temperature change per day of a survey into the list readings. A change may be positive, zero or negative, and the same change can be logged on several days.
Collapse repeats so that each value present in readings is considered once, then rank those values from largest down. Return the value in third place. When the survey holds fewer than three different values, return the largest value instead.
Example 1
The different values logged are 12, 9, 4 and -6. Ranking them from largest down gives 12 first, 9 second and 4 third, so 4 is returned.
Example 2
Every day logged the same change, so the survey holds one different value. That is fewer than three, so the largest value 7 is returned.
Example 3
All three values differ. Ranked from largest down they are 2147483647, 0 and -2147483648, so third place holds -2147483648.
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 third_max(readings: list[int]) -> int:public int thirdMax(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.