Overview
In LIS, we determine the longest sequence of strictly increasing elements. The DP state `dp[i]` stores the max length ending exactly at index `i`.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
The Longest Increasing Subsequence (LIS) pattern is foundational for many sequence-based DP problems.
In LIS, we determine the longest sequence of strictly increasing elements. The DP state `dp[i]` stores the max length ending exactly at index `i`.
For every element `i`, we look back at all previous elements `j`. If `nums[i] > nums[j]`, we can extend the sequence ending at `j`.
This exact O(N^2) double-loop pattern solves variants like Longest Divisible Subset, Bitonic Subsequence, and Longest String Chain.
While the DP pattern is O(N^2), pure LIS length can be optimized to O(N log N) using binary search with a `tails` array.