Edit distance
Harddynamic programmingstring
Return the fewest operations to turn word a into word b. Allowed: insert a character, delete one, or replace one. (Spell checkers use this to suggest nearby words.)
Example 1
Input: a = "horse", b = "ros" Output: 3
horse → rorse (replace) → rose (delete) → ros (delete).
Example 2
Input: a = "intention", b = "execution" Output: 5
Constraints
- 0 ≤ a.length, b.length ≤ 500
- Lowercase English letters
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {string} a
* @param {string} b
* @return {int}
*/
function minDistance(a, b) {
}