← Back to Algorithms

Longest Common Subsequence

Finds the longest subsequence present in both strings in the same relative order.

Medium

How it Works

The Longest Common Subsequence (LCS) problem is to find the longest subsequence common to two sequences. This algorithm uses a 2D table to store the lengths of LCS of substrings and builds the solution in a bottom-up manner.