-
Notifications
You must be signed in to change notification settings - Fork 157
Description
Problem formulation of the "Shortest Transformation Sequence":
Given two words. start and end, and a dictionary containing an array of words, return the length of the shortest transformation sequence to transform start to end. A transformation sequence Is a series of words in which:
• Each word differs from the preceding word by exactly one letter.
• Each word in the sequence exists in the dictionary.
lf no such transformation sequence exists, return 0.
I was a bit confused by the solution on p. 275:
if start == end: return 1
From the definition it might be unclear if start and end words are part of the transforamtion sequence or not.
If start and end are equal then they can not be consecutive elements of the transformation sequence, since it would contradict 1st requirement.
Then the only way start and end words are part of the transformation sequence if start and end are separated by another word. In that case the lenght of the transformation is at least 3.
If start and end words are not part of the transformation sequence, then to conclude that the lenght of the transformation sequence is 1 we need to find a single connecting word which might not be true (e.g. dictionary = [start]).