Find a Strictly Increasing Subsequence with Limited Numeric Steps
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Other
### Problem
Choose a subsequence of `nums` that is strictly increasing and whose neighboring retained values differ by at most k. Return its maximum length, retaining original index order while permitting skipped positions.
```cpp
class Solution {
public:
int lengthOfLIS(vector<int>& nums, int k);
};
```
### Examples
**Example 1:**
```text
Input: nums = [1,3,2,4], k = 2
Output: 3
Explanation: Both [1,3,4] and [1,2,4] work. All four values are not increasing.
```
**Example 2:**
```text
Input: nums = [2,2,3], k = 1
Output: 2
Explanation: Equal 2 values cannot extend a strictly increasing subsequence, but either occurrence can precede 3.
```
### Constraints
- `1 <= nums.length <= 100000`.
- `1 <= nums[i], k <= 100000`.
### Clarifying Questions
- May equal values appear consecutively in the selected subsequence? No; increase is strict.
- Can positions be skipped? Yes, while keeping their original order.
- Is a gap equal to `k` allowed? Yes.
- Is the bound on adjacent selected values or all pairs? Adjacent selected values.
```hint Check the boundary
Check repeated values and a numeric gap exactly equal to `k`.
```
Overview: Find the maximum length of a strictly increasing subsequence whose adjacent selected values differ by at most k.