Fundamentals/Edit Distance
← PrevNext →
Given two sequences word1 and word2, return the minimum number of single-element operations needed to convert word1 into word2. The allowed operations are insert one element, delete one element, or replace one element.
Input
word1: the source sequence (string or array)
word2: the target sequence (string or array)
Output
The minimum number of insert, delete, or replace operations to transform word1 into word2.
Examples
Example 1
Inputword1 = [1, 3, 5], word2 = [2, 4, 6]
Output3
Example 2
Inputword1 = [1], word2 = [2]
Output1
Constraints
Elements are compared with strict equality.
Result is always >= 0.