> For the complete documentation index, see [llms.txt](https://liuzhenglaichn.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://liuzhenglaichn.gitbook.io/algorithm/longest-common-subsequence.md).

# Longest Common Subsequence

Find the longest common subsequence (LCS) among to array of numbers/characters.

Example:

```
a = "abcde", b = "acef"
LCS = "ace"
```

The optimal solution is a DP solution with time complexity `O(MN)` and space complexity `O(min(M, N))`.

## Problems

* [1143. Longest Common Subsequence (Medium)](https://leetcode.com/problems/longest-common-subsequence/)
