LeetCode 2407 Longest Increasing Subsequence II - Problem Statement

The problem

Find the longest strictly increasing subsequence where adjacent elements differ by at most kk. For [4,2,1,4,3,4,5,8,15] with k=3k=3, the answer is 55 from subsequence [1,3,4,5,8].

Unlike standard LIS, the difference constraint requires a different approach. You'll use a segment tree for efficient range queries.

Example: [4,2,1,4,3,4,5,8,15], k=35. Longest subsequence with adjacent difference at most kk.

Constraints: 11 \le nums.length 105\le 10^5, 11 \le nums[i], k105k \le 10^5.