Model as a graph. Words are nodes. Two words are connected if they differ by exactly one letter.
BFS from beginWord. First time you reach endWord, return the path length.
Optimization: instead of comparing all word pairs (expensive), for each word, generate all possible one-letter changes and check if they're in the dictionary.