← All problems

Longest Common Subsequence

Medium dynamic programmingstrings LeetCode ↗
Given two strings, find the length of their longest common subsequence — the longest sequence that appears as a subsequence (not necessarily contiguous) in both strings.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(mn), Space O(mn)

Common pitfalls

  • Confusing subsequence with substring
  • Off-by-one in table indexing

Your solution

Log in to save your code and track progress.