Longest Increasing Subsequence
Implement lengthOfLIS
Given an array of integers, find the length of its longest strictly increasing subsequence — a run of elements, not necessarily touching in the original array, that keeps its relative left-to-right order while strictly climbing in value at every step.
Every index can either join the subsequence being built or sit out, and whether it's allowed to join depends only on which number was chosen right before it. That makes "the best subsequence achievable from here onward, given the last number picked" a self-contained sub-problem: once it's known for every index and every possible predecessor, the overall answer just picks the largest one reachable from the very start. Since a number can only ever extend a run that ended on something smaller, sweeping through the array once and, for each position, checking every earlier position that could have preceded it is enough to fill in every sub-problem's answer using only ones already finished.
Example 1:
Input: nums = [11,4,7,2,9,6,14,3]
Output: 4
Example 2:
Input: nums = [2,5,2,8,6,9]
Output: 4
Example 3:
Input: nums = [5,5,5,5,5,5,5]
Output: 1
+ 7 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ nums.length ≤ 12 - ●
-1000 ≤ nums[i] ≤ 1000
nums =
[11, 4, 7, 2, 9, 6, 14, 3]