Trains the technique from
LeetCode 594Longest Harmonious 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 cold-store probe logs whole-degree temperatures into the list readings. Values may be below zero.
A technician wants to pull out a sample: any collection of readings taken from the log, chosen freely and without regard to where they sat in the log. A sample is tight when the difference between its largest and its smallest reading is exactly one degree.
Return the number of readings in the largest tight sample. If no tight sample exists, return 0.
Example 1
Taking both readings of -1 and both readings of 0 gives a sample of four whose smallest is -1 and whose largest is 0, one degree apart.
Example 2
The two 4s together with the three 5s make a sample of five running from 4 to 5. Adding the 6 as well would stretch the spread to two degrees.
Example 3
No two of these readings differ by exactly one degree, so no tight sample can be formed and the answer is 0.
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_paired_sample(readings: list[int]) -> int:public int longestPairedSample(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.