Dynamic Programming
Medium
Longest Increasing Subsequence
Given an integer array nums, return the length of the longest strictly increasing subsequence.
10 min read
Solve on LeetCodeProblem Understanding
A subsequence is derived by deleting some or no elements without changing the order.
Example: [10, 9, 2, 5, 3, 7, 101, 18]
- One LIS:
[2, 3, 7, 101] - Length: 4
Algorithm Strategy
We define dp[i] as the length of the LIS ending at index i.
Recurrence:
For each j < i, if nums[j] < nums[i], we can extend the subsequence ending at j.dp[i] = max(dp[i], dp[j] + 1)
Base Case: dp[i] = 1 (subsequence of itself).
Interactive Visualization
Step 1 / 1
Initializing...
1x
See the Logic in Motion
Stop memorizing code. Unlock the full interactive visualizer to master the logic step-by-step.ON THIS PAGE
- Problem Understanding
- Algorithm Strategy
- Interactive Visualization
- Dry Run
- Edge Cases & Common Mistakes
- Solution
- Complexity Analysis
Stop Guessing, Start Mastering.
Build the FAANG intuition. Master this pattern with optimized implementations, visual dry runs, and our curated collection of high-yield problems.
