Problem
You get two strings word1 and word2. Return the minimum number of operations that change word1 into word2.
Each operation changes word1 in one of three ways. You can insert one character at any position. You can delete one character. You can replace one character with a different character.
Example 1
- Input:
- word1 = "cart", word2 = "chart"
- Output:
- 1
- Explanation:
- Insert
hafterc.
Example 2
- Input:
- word1 = "stone", word2 = "tones"
- Output:
- 2
- Explanation:
- Delete the first
sto get"tone". Then insertsat the end to get"tones".
Example 3
- Input:
- word1 = "abc", word2 = ""
- Output:
- 3
- Explanation:
- Delete all three characters.
Constraints
- 0 <= word1.length, word2.length <= 500
- word1 and word2 have only lowercase English letters.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- One Edit Distance
Coding
- All Nodes Distance K in Binary Tree
Coding · Binary Tree · Breadth-First Search · Depth-First Search
- Count Pairs of Points With Distance k
Coding
- Count Subtrees With Max Distance Between Cities
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Amazon
Leetcode 72. Edit Distance
Reported Aug 31, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View sourceLinkedIn
Leetcode 72. Edit Distance
Reported Jan 11, 2026 · 3 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View source