solulubeta
Sign in
Recursion & Memo / DP patterns for coding tests
04.12 · Problem

Edit Distance

Hard Two strings, three moves LC 72 Pro

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
Mark this problem as solved when you are finished.

Item 38 of 44 · updated 2026-10-13