Skip to main content
All Questions

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.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.