Longest increasing subsequence

medium

dp[i] means 'ending exactly at i' - anchoring the subproblem is what makes the recurrence work. Then switch to patience sorting and watch binary search remove the inner loop.

Best O(n log n) patienceWorst O(n²) DPSpace O(n)
Loading the longest increasing subsequence engine…

Where to go next