A transformation sequence from word `beginWord` to word `endWord` using a dictionary `wordList` is a sequence of words `beginWord -> s1 -> s2 -> ... -> sk` such that: (1) Every adjacent pair of words differs by a single letter. (2) Every `si` is in `wordList`. (3) `sk == endWord`. Given two words and a dictionary, return the number of words in the shortest transformation sequence, or 0 if no such sequence exists.
Shortest Path BFS
This is a shortest path problem in an unweighted graph where each word is a node and an edge exists between words that differ by exactly one letter. BFS is the ideal algorithm for finding the shortest path. To optimize finding neighbors, we can use 'pattern' matching (e.g., `*ot` matches `hot`, `dot`, `lot`).