Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Edit Distance

Medium

Topics
StringDynamic Programming

Given two strings word1 and word2, return the minimum number of operations (insert, delete, or replace a character) to convert word1 into word2.

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
  • Inputs consist of lowercase English letters.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access