When to Use

Pattern triggers

Look for these signals in the problem:

  • "Edit distance" or "transform one to another": Comparing two sequences character by character with operations.
  • "Longest common" subsequence/substring: Finding shared structure between two sequences.
  • "Grid path" counting or optimization: State is current position (row, col) in the grid.
  • "Two sequences" comparison: When processing two strings/arrays in parallel.
  • "Distinct subsequences" or counting matches: Counting ways to form one sequence from another.