Longest Increasing Subsequence

You've learned prefix sums. Now find the longest increasing subsequence and optimize with binary search.

47 lessons
172 min
Codeforces: 1300-1900LeetCode: 1500-1900

Lessons

1. Intro

The Goal

4m

2. Vocabulary - Subsequence

The definition

4m

3. LeetCode 300 Longest Increasing Subsequence - Problem Statement

Classic DP problem

3m1 problems

4. LeetCode 300 Longest Increasing Subsequence - Why Greedy Fails

The trap

3m

5. LeetCode 300 Longest Increasing Subsequence - State Design

What dp[i] means

3m

6. LeetCode 300 Longest Increasing Subsequence - Transition

The recurrence

3m

7. LeetCode 300 Longest Increasing Subsequence - Implementation

The code

4m1 problems

8. LeetCode 300 Longest Increasing Subsequence - Walkthrough

Tracing the O(n^2) algorithm

4m

9. Challenge: LIS Reconstruction

Finding the actual subsequence

4m

10. Quiz: LIS State Design

Why ending at i

3m1 problems

11. Quiz: LIS Basics

Knowledge check

3m1 problems

12. Lessons from LIS

summary

4m

13. LeetCode 300 Longest Increasing Subsequence - Binary Search Optimization

The optimization idea

4m

14. LeetCode 300 Longest Increasing Subsequence - Binary Search Implementation

O(n log n) code

4m

15. LeetCode 300 Longest Increasing Subsequence - Binary Search Walkthrough

O(n log n) algorithm trace

4m

16. Why Binary Search Works

Understanding the tails array

4m

17. Quiz: LIS Optimization

Knowledge check

3m1 problems

18. LeetCode 673 Number of Longest Increasing Subsequences - Problem Statement

Counting all LIS

3m1 problems

19. LeetCode 673 Number of Longest Increasing Subsequences - Dual State

Length and count

3m

20. LeetCode 673 Number of Longest Increasing Subsequences - Implementation

The code

4m1 problems

21. LeetCode 673 Number of Longest Increasing Subsequences - Walkthrough

Counting subsequences

4m

22. Quiz: Counting LIS

When counts add up

3m1 problems

23. LeetCode 354 Russian Doll Envelopes - Problem Statement

2D LIS variant

4m1 problems

24. LeetCode 354 Russian Doll Envelopes - Walkthrough

2D LIS reduction

4m

25. LeetCode 1048 Longest String Chain - Problem Statement

LIS on string predecessors

4m1 problems

26. LeetCode 1048 Longest String Chain - Walkthrough

LIS on strings

4m

27. LeetCode 368 Largest Divisible Subset - Problem Statement

LIS with divisibility

3m1 problems

28. LeetCode 368 Largest Divisible Subset - The LIS Connection

Hidden pattern

3m

29. LeetCode 368 Largest Divisible Subset - Implementation

The code

4m1 problems

30. LeetCode 368 Largest Divisible Subset - Walkthrough

LIS with divisibility

4m

31. Quiz: LIS Variants

Recognizing the pattern

3m1 problems

32. Maximum Sum Increasing Subsequence - Problem Statement

Classic variation

3m1 problems

33. Maximum Sum Increasing Subsequence - State Change

Sum instead of length

3m

34. Maximum Sum Increasing Subsequence - Implementation

The code

4m1 problems

35. Maximum Sum Increasing Subsequence - Walkthrough

Weighted LIS

4m

36. Challenge: Max Sum IS Reconstruction

Finding the optimal subsequence

4m

37. Longest Bitonic Subsequence - Problem Statement

Bidirectional LIS

3m1 problems

38. Longest Bitonic Subsequence - Two Passes

Forward and backward

3m

39. Longest Bitonic Subsequence - Implementation

The code

4m1 problems

40. Longest Bitonic Subsequence - Walkthrough

Two-directional LIS

4m

41. Quiz: Bitonic Structure

Understanding the approach

3m1 problems

42. Minimum Deletions for Sorted - Problem Statement

LIS application

3m

43. Minimum Deletions for Sorted - Implementation

LIS for non-decreasing

6m

44. Pattern - LIS Family

Recognizing LIS problems

4m

45. Challenge: LIS in O(n log n) Space O(n)

Understanding space usage

4m

46. What's Next

Preview of LCS and Edit Distance

4m

47. Section Recap

What we learned

5m

Practice Problems

1.

The classic two-string DP that shows up everywhere. Foundation for edit distance, diff tools, and sequence alignment.

2.
Edit DistanceLeetCodehard

LCS plus a third operation. Powers spell checkers and translation scoring. Teaches multiple transitions from the same state.

3.

Shifts from "find the best" to "count all ways." When chars match, you add paths instead of taking max. Classic interview problem.

4.

Covered with full walkthrough in this section.

5.

Covered with full walkthrough in this section.

6.

Covered with full walkthrough in this section.

7.

Covered with full walkthrough in this section.

8.

Covered with full walkthrough in this section.

9.

Covered with full walkthrough in this section.

10.

Covered with full walkthrough in this section.

11.
Shortest and Longest LISCodeforcesmedium

Construct sequences with min/max LIS given constraints. Tests deep understanding of LIS structure.

12.
LIS or Reverse LIS?Codeforcesmedium

Maximize min(LIS, reverse LIS) through rearrangement. Beautiful observation about LIS symmetry.

13.
CopyCopyCopyCopyCopyCodeforceseasy

LIS of array concatenated n times. Elegant reduction to counting distinct elements.

14.
LIS of SequenceCodeforceshard

Classify elements by their role in all LIS. Advanced understanding of LIS uniqueness.

15.
XOR Specia-LIS-tCodeforceseasy

XOR of LIS lengths across subarrays. Parity observation makes complex problem simple.

16.

LIS with bounded gaps using segment tree. Advanced data structure optimization of LIS.

17.
Good SequencesCodeforcesmedium

LIS where adjacent elements share a prime factor. Combines number theory with LIS.

18.
Bubble Sort GraphCodeforcesmedium

Find max independent set in bubble sort graph. Reduces to LIS via inversions.

19.
Consecutive SubsequenceCodeforcesmedium

Find longest subsequence of consecutive integers. LIS variant with value tracking.

20.
The ContestCodeforcesmedium

Partition array into three sorted parts. LIS ideas with multiple segments.

21.
Upgrading CitiesCodeforceshard

Find cities reachable from all but one. DAG + LIS-style reachability.

22.
K-goodCodeforcesmedium

Represent number as sum of k distinct remainders. Number theory + construction.

23.

LIS with values - maximize sum of beauties in increasing height subsequence. Segment tree optimization.

Ready to start learning?

Access all 47 lessons with interactive content and progress tracking.