Gamified challenge · BFS on an implicit graph
You get a start word, an end word and a list words, all in capital letters and all the same length. One move changes exactly one letter in place, and every word you land on must be in words (the start word itself doesn't have to be).
Write ladder(start, end, words) that returns the shortest ladder as a list of words, beginning with start and ending with end. Any shortest ladder passes. If start equals end, return [start]; if no ladder exists, return an empty list.
Example: ladder("COLD", "WARM", ["CORD", "CARD", "WARD", "WARM", "WORD", "WORM", ...]) → ["COLD", "CORD", "WORD", "WARD", "WARM"] (4 changes; COLD → CORD → CARD → WARD → WARM is just as good).
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google