ā Back
š¼ Rising Tower
Build the Longest Increasing Subsequence ⢠O(n²) DP visualization
Array:
š² Random
ā¶ Find LIS
š¼ Tower Visualization
š DP Array (dp[i] = LIS ending at index i)
š LIS DP O(n²)
dp[i] = LIS length ending at i
for each j < i:
if arr[j] < arr[i]:
dp[i] = max(dp[i], dp[j]+1)
Answer = max(dp[i])
Array Size
-
Comparisons
0
LIS Length
?
š” Key Insight
For each element, look at ALL
previous smaller elements and
take the best LIS to extend.
There's also O(n log n) using
binary search + patience sorting!