Practice Longest Increasing Subsequence II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Hard#2407
LeetCode ProblemLongest Increasing Subsequence II
Problem Statement
Find a subsequence of nums, preserving index order, whose values are strictly increasing and whose consecutive value differences are each at most k. Return its greatest possible length.
Source: Longest Increasing Subsequence II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [4,2,1,4,3,4,5,8,15], k = 3
Output
5
# Example 2
Input
nums = [7,4,5,1,8,12,4,7], k = 5
Output
4
# Example 3
Input
nums = [1,5], k = 1
Output
1
Constraints
1 <= nums.length <= 10^5
1 <= nums[i], k <= 10^5
Related LeetCode Problems
Practice more problems similar to Longest Increasing Subsequence II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.