AiTechWorlds
AiTechWorlds
Visualize the O(n²) LIS dynamic programming table filling step-by-step, with synced multi-language code.
| 3 | 1 | 8 | 2 | 5 | 9 | 4 | 7 | |
|---|---|---|---|---|---|---|---|---|
| LIS | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
def lis(a):
n = len(a)
dp = [1] * n
for i in range(1, n):
for j in range(i):
if a[j] < a[i]:
dp[i] = max(dp[i], dp[j] + 1)
return max(dp)Longest Increasing Subsequence finds the longest subsequence whose elements are strictly increasing. The O(n²) DP sets dp[i] to the best length ending at index i.
| Time | O(n²) |
| Space | O(n) |
The Longest Increasing Subsequence (LIS) Visualizer animates the O(n²) dynamic programming solution. dp[i] holds the length of the longest increasing subsequence ending at index i, computed by checking all earlier elements smaller than a[i]. The answer is the maximum dp value. Time is O(n²) and space is O(n).
Press Play
Watch dp[i] update by comparing each earlier element a[j] < a[i].
Step through
Use Step Forward/Back or the timeline to follow each comparison.
Read the code
View the LIS DP in C++, Java, Python, or JavaScript and copy it.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.