Skip to content

Practice Edit Distance

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#72
LeetCode Problem

Edit Distance

Problem Statement

Given strings word1 and word2, return the smallest number of single-character edits needed to turn word1 into word2. Each edit can insert one character, delete one character, or replace one character with another.

Source: Edit Distance on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
word1 = "horse", word2 = "ros"
Output
3

# Example 2

Input
word1 = "intention", word2 = "execution"
Output
5

Constraints

0 <= word1.length, word2.length <= 500
word1 and word2 consist of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Edit Distance.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.