Dynamic Programming

Problem shape

Intermediate
4
8
15
16
23
42
Core idea

Track the smallest possible tail value for increasing subsequences of each length.

Step 1 / 5
Problem shape
Current lesson

Longest Increasing Subsequence Lab

Dynamic Programming Intermediate

Longest Increasing Subsequence

Welcome to the Longest Increasing Subsequence algorithm lab. Track the smallest possible tail value for increasing subsequences of each length. Use it when: Use for sequence ordering and minimum-removal style problems. The time complexity is O(n log n), and the space complexity is O(n). The pseudocode is: tails = [] for x in nums i = lower_bound(tails, x) tails[i] = x answer = length(tails) As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(n log n)

Space

O(n)

Pseudocode

tails = []
for x in nums
  i = lower_bound(tails, x)
  tails[i] = x
answer = length(tails)
Open deeper structure lesson
1.0x