Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Patience sorting: track the smallest possible tail for an increasing subsequence of each length.

Approach

Maintain array tails where tails[len-1] is the minimum tail of an LIS of length len. For each x, binary search lower_bound position and replace/append.

Why it works

Keeping tails minimal preserves the ability to extend to longer subsequences; length of tails is LIS length.

Code
Loading...
Complexity
Time: O(n log n)
Space: O(n)
Solution
Updated: 2026-02-23

Idea

Patience sorting: track the smallest possible tail for an increasing subsequence of each length.

Approach

Maintain array tails where tails[len-1] is the minimum tail of an LIS of length len. For each x, binary search lower_bound position and replace/append.

Why it works

Keeping tails minimal preserves the ability to extend to longer subsequences; length of tails is LIS length.

Code
Loading...
Complexity
Time: O(n log n)
Space: O(n)