Why it matters

LIS has elegant fast algorithm. Understanding shapes classical DP.

Advertisement

The architecture

Maintain tails[i]: smallest tail of length-(i+1) LIS.

Binary search insert.

LIS O(n log n)Tails arraysmallest tail per lenBinary searchinsert positionLIS length= tails.lengthReconstruct actual LIS via parent pointers; standard interview problem
LIS.
Advertisement

How it works end to end

tails: increasing.

Binary search: first tail >= x.

Replace or extend.

Length = tails size.