Here is the interview question prompt, presented for reference.
Imagine two words placed at the two ends of a ladder. Can you reach one word from another using intermediate words as rings of the ladder? Each successive or transition word has a difference of only one letter from its predecessor, and must belong to a provided dictionary. Can we achieve this using the shortest possible number of rings, and return that number?
Suppose we are given:
We have to find a minimum length sequence of words so that the start word is transformed into the end word. A word is only transformable to the other if they have a difference of one letter. Consider a dictionary, start word startW, and end word endW below:
Dictionary: {hope, hole, bold, hold, cold, sold, dold}
startW: bold
endW: hope
Two possible sequences of transformations are given below:
Sequence 1: bold->cold->sold->hold->hole->hope
Sequence 2: bold->hold->hole->hope
The length of the second sequence is 4, which is shorter than sequence 1 with a length of 6. Hence the acceptable answer is 4. We make the following assumptions for this problem:
abc is not the same as ABC.5050n be the length of each word and m be the number of wordsO((m^2)*n)O(m*n)You can see the full challenge with visuals at this link.
Challenges • Asked about 6 years ago by Team AlgoDaily
This is the main discussion thread generated for Climbing the Word Ladder.