Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 72 Edit Distance - Problem Statement

LeetCode 72

This is Edit Distance from LeetCode, also called Levenshtein Distance. Given two strings, find the minimum operations to convert one to the other. You can insert, delete, or replace a character. For "horse" and "ros": horse → rorse → rose → ros. 33 operations.

Constraints: m,n500m, n \le 500. Brute-force recursion is exponential. Build up answers for shorter prefixes first to avoid recomputation.