Overview
LIS is a fundamental pattern where you build the answer for element `i` by looking backwards at all elements `j < i`.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Find the length of the longest strictly increasing subsequence in an array using an O(N^2) dynamic programming approach.
LIS is a fundamental pattern where you build the answer for element `i` by looking backwards at all elements `j < i`.
`dp[i]` represents the length of the Longest Increasing Subsequence that STRICTLY ends at index `i`.
For a fixed `i`, scan all `j < i`. If `nums[i] > nums[j]`, then we can extend the LIS ending at `j`. `dp[i] = max(dp[i], dp[j] + 1)`.
The final answer is not necessarily `dp[n-1]`. The LIS could end anywhere, so we must return the maximum value in the entire `dp` array.