(index1: int, index2: int)
| 27 | |
| 28 | @functools.cache |
| 29 | def min_distance(index1: int, index2: int) -> int: |
| 30 | # if first word index overflows - delete all from the second word |
| 31 | if index1 >= len_word1: |
| 32 | return len_word2 - index2 |
| 33 | # if second word index overflows - delete all from the first word |
| 34 | if index2 >= len_word2: |
| 35 | return len_word1 - index1 |
| 36 | diff = int(word1[index1] != word2[index2]) # current letters not identical |
| 37 | return min( |
| 38 | 1 + min_distance(index1 + 1, index2), |
| 39 | 1 + min_distance(index1, index2 + 1), |
| 40 | diff + min_distance(index1 + 1, index2 + 1), |
| 41 | ) |
| 42 | |
| 43 | return min_distance(0, 0) |
| 44 |
no outgoing calls
no test coverage detected