Shortest Word Edit Path
2 min readOct 21, 2021
--
Use Python To Solve Real Problems
Given two words source
and target
, and a list of words words
, find the length of the shortest series of edits that transforms source
to target
.
Each edit must change exactly one letter at a time, and each intermediate word (and the final target
word) must exist in words
.
If the task is impossible, return -1
.
Examples:
source = "bit", target = "dog"
words = ["but", "put", "big", "pot", "pog", "dog", "lot"]output: 5
explanation…