sort envelopes by width ascending, then by height descending (to avoid same-width nesting). then find longest increasing subsequence (LIS) on heights.
use binary search LIS: maintain array of smallest tail values for each length. for each envelope, find position to extend or start new sequence.
key insight
sorting by width then height (descending) converts 2d problem to 1d LIS problem. binary search LIS gives O(n log n) solution.
complexity
O(n log n) time for sorting and LIS. O(n) space for LIS array. efficient solution.