73. Longest Increasing Subsequence

Return the length of the longest strictly increasing subsequence of nums (elements keep their order but need not be adjacent). Can you do it in O(n log n)?

Example 1

Input: nums = [10,9,2,5,3,7,101,18]
Output: 4
Explanation: One LIS is 2, 3, 7, 101.

Example 2

Input: nums = [0,1,0,3,2,3]
Output: 4
Hint 1

O(n²): dp[i] = 1 + max(dp[j]) for j < i with nums[j] < nums[i].

Hint 2

O(n log n): keep the smallest possible tail for each length and binary-search where x goes.

Dynamic ProgrammingBinary Search