Trains the technique from
LeetCode 2407Longest Increasing Subsequence IIThis 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.
Gauge readings are given as nums. A climb picks readings from the list, keeping their order, so that every reading is strictly larger than the one before it while the rise from one to the next is never more than k.
Return how many readings the longest climb holds.
Example 1
The climb 6, 7, 8 rises by one each time, and no longer climb keeps every step inside seven: reaching 13 then 19 is a step of six but 19 to 21 to 25 cannot be extended back far enough to beat three.
Example 2
Each reading is two above the last, which the cap just allows, so the whole list is one climb.
Example 3
Every step is two, which the cap forbids, so no climb holds more than one reading.
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 length_of_l_i_s(nums: list[int], k: int) -> int:public int lengthOfLIS(int[] nums, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.