Word Ladder

Hard · Graphs · about 30 minutes

Asked at Amazon, Meta, Google, LinkedIn, Quora.

Turn beginWord into endWord one letter at a time. Each step swaps exactly one letter, and every word you pass through after the start (including endWord) must appear in wordList. Return how many words the shortest such chain contains, counting both the first and last word, or 0 if no chain exists. All words are lowercase and equally long.

Related guides