Lesson 76 of 86AdvancedPro Interactive Lesson

Longest Increasing Subsequence (LIS)

Track increasing subsequences in their original order. Selected elements may be separated by unused elements.

Core Intuition & How It Works

Longest Increasing Subsequence (LIS) finds the longest strictly increasing subsequence of an array. Classic DP solves it in O(n²), while maintaining smallest ending tails with binary search (patience sorting) achieves O(n log n).

In the Byte Sized Algorithms interactive classroom, you can step forward and backward through this algorithm with your keyboard while watching the visual diagram, memory state, and highlighted pseudocode update together.

Time & Space Complexity

MetricComplexity
Time ComplexityO(n²) DP, O(n log n) with binary search
Space ComplexityO(n)
Topic ChapterChapter 13: Dynamic Programming
Difficulty LevelAdvanced

Key Pattern to Recognize

In the O(n log n) method, binary search the tails array for the first element ≥ x (strictly increasing) and replace it.

Common Pitfalls & Edge Cases

Assuming the tails array itself is the actual LIS (its length is exact, but reconstructing the sequence requires predecessor pointers).

Real-World & Technical Interview Applications

Box stacking, Russian doll envelopes, diff utilities, and version dependency chains.

Unlock the full course

All 86 lessons across 15 chapters

View pricing

Delete account

This permanently deletes your account and ends any Pro access.