Graph Theory37 sections · 1633 units
Open in Course

LeetCode 127 Word Ladder - Problem Statement

Seeing the Graph

In Word Ladder, nodes are words. Two words are connected if they differ by exactly one letter. For example, hit and hot differ only in the third letter, so they are neighbors. Your graph has one node per word in the word list (plus beginWord and endWord). Edges connect words that are one letter apart. The goal is the shortest path from beginWord to endWord. Since all edges have weight 11, BFS finds the shortest path.

The tricky part is finding neighbors efficiently without comparing every pair of words.