Common Mistakes

Common errors to avoid

  • Wrong base case initialization: First row/column often needs special handling. Think about empty string or starting position meaning.
  • Index confusion: dp[i][j] might represent characters 00 to i1i-1, not 00 to ii.

Be consistent with your indexing convention.

  • Not considering all transitions: In edit distance, forgetting one operation type leads to wrong minimum.
  • Space optimization breaks reconstruction: If you need the actual sequence (not just length), maintain full table or parent pointers.