Patience sorting / binary search LIS is the efficient answer Apple expects when n is large.
Enable JavaScript for the full StreamPrep guide.