Shortest Word Edit Path

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
Yaokun Lin @ MachineLearningQuickNotes

Actuary | ML Practitioner | Apply Tomorrow's Technology to Solve Today's Problems