Browse Curriculum
Dynamic Programming
Medium

Longest Increasing Subsequence

Given an integer array nums, return the length of the longest strictly increasing subsequence.

Problem 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

Watch how dp[i] checks all previous dp[j] values to find the maximum extensions.

Click 'Randomize' to test different arrays.

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.