Trains the technique from
LeetCode 1027Longest Arithmetic 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 glass studio keeps readings, the peak kiln temperature of every firing it has run, listed oldest firing first.
A ladder is a selection of two or more firings, kept in the order they appear in readings, such that the change from each selected firing to the next selected one is the same signed amount every time. The firings in a ladder need not be neighbours in the log, and that shared amount may be negative or zero.
Return the number of firings in the longest ladder the log admits.
Example 1
The firings reading 60, 118 and 176 rise by 58 from one to the next, so a ladder of three firings is reported.
Example 2
Every firing reads 77, so the whole log is a ladder whose shared change is 0.
Example 3
The firings reading 8, 26, 44 and 62 each sit 18 above the one before, giving four firings in log order.
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_ladder(readings: list[int]) -> int:public int longestLadder(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.