Find the longest strictly increasing subsequence with bounded adjacent differences.
Unlock detailed company stats for this questionUpgrade
Given an array of integers and an integer k, find the length of the longest subsequence such that: (1) the elements are strictly increasing, (2) the difference between any two consecutive elements in the subsequence is at most k, and (3) the relative order of the original array is maintained (a subsequence, not a subarray).
Example 1: arr = [7,1,4,5,8,8,10,6,7,7,7,8], k = 4 gives 6 via [1,4,5,6,7,8]. Example 2: arr = [3,1,2,6,10,11,4,5], k = 3 gives 4 via [1,2,4,5]. Example 3: arr = [5,4,3,2,1], k = 2 gives 1, since no two elements form an increasing pair. Hint: a variation of Longest Increasing Subsequence with an extra limit on adjacent differences.
Community answers
No answers contributed by the community yet.


