Shortest Word Transformation Sequence
Reported by candidates from Reddit's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Reddit reported this one in September 2026, and it's the classic word ladder. The whole solution hinges on one data structure: a queue driving a breadth-first search, backed by a hash set of the dictionary words. If you've got an OA invite for the next couple of days, this is the shape to recognize. You're finding the shortest path in an unweighted graph where words are nodes and one-letter changes are edges. Nobody hands you the graph, so you build it on the fly. If you blank on the BFS setup during the live assessment, StealthCoder is the invisible safety net that reads the problem and gives you a working solution.
The problem
You are given two different words, beginWord and endWord, and a dictionary wordList. A transformation changes exactly one letter, and every transformed word, including endWord, must appear in the dictionary. Return the number of words in the shortest valid transformation sequence from beginWord through endWord, counting both endpoints. Return 0 when no valid sequence exists. Function ladderLength(beginWord: String, endWord: String, wordList: String[]) → int Examples Example 1 beginWord = "hit" endWord = "cog" wordList = ["hot","dot","dog","lot","log","cog"] return = 5 One shortest sequence is hit → hot → dot → dog → cog, which contains five words. Example 2 beginWord = "hit" endWord = "cog" wordList = ["hot","dot","dog","lot","log"] return = 0 The endpoint is absent from the dictionary, so no valid transformation sequence exists. Example 3 beginWord = "a" endWord = "c" wordList = ["a","b","c"] return = 2 Changing a directly to c uses two words. Constraints 1 <= beginWord.length == endWord.length <= 10. 1 <= wordList.length <= 5000. All words have the same length and contain only lowercase English letters. beginWord and endWord are different. The dictionary contains no duplicate words.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: shortest path with equal-cost edges means BFS, not DFS. Put beginWord in a queue with a level of 1. For each word, try swapping each position with a through z, and check whether the new word is in the set. If it is, enqueue it and remove it from the set so you never visit it twice. Return the level when you pop endWord. Pitfalls: forgetting that endWord must be in the dictionary (Example 2 returns 0), counting edges instead of words (Example 3 returns 2, not 1), and comparing every pair of words, which is slow with 5000 words. Generating neighbors costs about 10 x 26 lookups per word, which is far cheaper. Note that beginWord doesn't need to be in the list. If the search runs dry, return 0. StealthCoder is your hedge if the live OA clock rattles you and the neighbor loop won't come out right.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Shortest Word Transformation Sequence cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as word ladder. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Reddit's OA.
Reddit reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Shortest Word Transformation Sequence FAQ
What's the trick to the Reddit word ladder problem?+
Treat words as graph nodes and run BFS from beginWord. The first time you reach endWord, the level count is your answer. Store the dictionary in a hash set for O(1) lookups, and delete words as you visit them so you don't loop.
Why BFS and not DFS?+
BFS explores level by level, so the first arrival at endWord is guaranteed shortest. DFS could find a long path first and would need to explore everything to prove it's shortest. With 5000 words, that blows up fast.
Does beginWord have to be in wordList?+
No. Only transformed words, including endWord, must be in the dictionary. Start the queue with beginWord regardless. Example 3 shows this isn't a problem either way, since a is in the list there but the rule doesn't require it.
What's the most common wrong answer?+
Off-by-one on the count. The answer counts words, not transitions, so start at 1 for beginWord. Also check that endWord is in the set up front, or return 0 early. Example 2 tests exactly that case.
How do I prepare for this in 48 hours?+
Write the BFS from scratch twice with a set and a queue. Practice the neighbor generation loop over positions and letters a to z. Then test the three given examples by hand. That covers the core of this problem, including the no-path and single-letter cases.