Transforming words one letter at a time: replace $O(N^2)$ pairwise checks with $O(26 \cdot L)$ neighbor generation. Expand simultaneously from start and target, swapping frontiers to always expand the smaller set.
if (beginSet.size() > endSet.size()) swap(beginSet, endSet). This trims the branching volume from $O(b^d)$ down to $O(2 \cdot b^{d/2})$.
"Pairwise string comparison takes $O(N^2 \cdot L)$ time. Instead, for word of length $L$, mutate each character $26$ times and check membership in wordSet in $O(26 \cdot L)$ time."
"Standard BFS explodes with exponential branching $b^d$. Searching from both beginWord and endWord meets in the middle at depth $d/2$, reducing states searched to $2 \cdot b^{d/2}$."
"At each layer, we inspect beginSet.size() > endSet.size(). Swapping to always expand the smaller set ensures we minimize immediate branching."
"The moment a neighbor generated from beginSet is found in endSet, the two frontiers have touched: return length + 1 immediately."