04.12 · Problem
Edit Distance
Turn word1 into word2. Inserting, deleting or replacing one character costs 1. Return the fewest operations.
Examples
Example 1
Input: word1 = "horse", word2 = "ros"
Output: 3
horse → rorse (replace h with r) → rose (delete r) → ros (delete e).
solulu Pro
Continue this problem with Pro
Inside: step-by-step hints · 12 hidden tests · reference solutions · code editor.
Lifetime ₹1,999 ₹999 · Launch offer
Item 38 of 44 · updated 2026-10-13