This practice workspace is built for desktop. Open it on a larger screen to start solving.
Edit Distance
Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2.
You have three operations permitted on a word:
- Insert a character
- Delete a character
- Replace a character
Classic DP: dp[i][j] = edit distance between word1[0..i-1] and word2[0..j-1].
- If
word1[i-1] == word2[j-1]:dp[i][j] = dp[i-1][j-1] - Otherwise:
dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])(delete, insert, replace)
Examples
Constraints
- 0 <= word1.length, word2.length <= 500
- word1 and word2 consist of lowercase English letters.
Preview Mode
This is a read-only preview of DSAMind's AI coaching. Sign up to get custom feedback on your own solution.
Your approach
- Pattern:Dynamic Programming
- Time:O(N)
- Space:O(1)
Complete approach — pattern and complexity both named.
Coach
What you got right
You correctly matched the sorted input requirement and implemented a linear-time scan using two pointers.
Where it diverged
No divergence detected. The code correctly aligns with the stated approach.
Next attempt: focus on
Try solving related sliding window problems to build familiarity with two-pointer variants.
Signals
No signals fired — clean run, you stayed in flow.