Word Ladder

Prereq: BFS on Graph

Word Ladder is "a puzzle begins with two words, and to solve the puzzle one must find a chain of other words to link the two, in which two adjacent words (that is, words in successive steps) differ by one letter."

For example: COLD → CORD → CARD → WARD → WARM

Given a start word, an end word and a list of dictionary words. Determine the minimum number of steps to go from the start word to the end word using only words from the dictionary.

Input:

start = "COLD"
end = "WARM"
word_list = ["COLD", "GOLD", "CORD", "SOLD", "CARD", "WARD", "WARM", "TARD"]

Output:

4

Explanation: We can go from COLD to WARM by going through COLD → CORD → CARD → WARD → WARM

Try it yourself

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

  >>> a = [1, 2, 3]
  >>> a[-1]
  3

Get premium for instant access to all content and solutions

Upgrade