Given an integer array nums, you need to find the length of the longest strictly increasing subsequence.
A subsequence is a sequence that can be derived from the original array by deleting some or no elements without changing the order of the remaining elements. For example, [3,6,2,7] is a subsequence of [0,3,1,6,2,2,7].
An increasing subsequence means each element is strictly greater than the previous one. Your goal is to find the maximum possible length of such a subsequence.
Example: In array [10,9,2,5,3,7,101,18], one possible longest increasing subsequence is [2,3,7,18] with length 4.
Input & Output
Visualization
Time & Space Complexity
For each of n elements, we perform binary search on tails array which can be at most n elements long
Additional tails array that stores at most n elements in worst case
Constraints
- 1 ≤ nums.length ≤ 2500
- -104 ≤ nums[i] ≤ 104
- Follow up: Can you come up with an O(n log n) solution?