Developer

This experience deserves a bigger screen

The DSA Visualizer is designed for deep focus,
side-by-side code, and real-time execution insight.

On small screens, that level of clarity can't be preserved.

Open on a tablet (landscape) or desktop for the intended experience.

Desktop experience preview

Longest Common SubsequenceStep-by-Step Visualization

Used in diff tools and genetic alignment, LCS finds the longest shared sequence of characters.

Problem Statement

Given two strings text1 and text2, return the length of their longest common subsequence.

Approach

dp[i][j] represents LCS length of text1[0..i] and text2[0..j]. If chars match, 1 + dp[i-1][j-1]. Else, max(dp[i-1][j], dp[i][j-1]).

Time & Space Complexity

Time complexity is O(M * N). Space complexity is O(M * N).

Interactive Visualization

Loading Interactive Visualizer...

Click "Play" or use arrow keys to step through the execution.