Word Ladder
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon reported this Word Ladder variant in September 2026, and the input size is the first thing to read. With up to 5000 words, you can't try every ordering of the dictionary, and you can't do anything exponential. Words top out at 10 letters, which is the hint. This is shortest path on an implicit graph, so it's breadth-first search. The twist in this version is the edge case: if beginWord equals endWord, the answer is 1 only when that word is in the dictionary. If you blank on the OA, StealthCoder is the safety net running invisibly, but the pattern below is short enough to carry in your head.
The problem
You are given beginWord, endWord, and a dictionary wordList. A transformation changes exactly one character, and every transformed word, including endWord, must appear in the dictionary. Return the number of words in the shortest valid sequence from beginWord through endWord, counting both endpoints. Return 0 when no sequence exists. If the two endpoints are equal, the answer is 1 only when that word appears in the dictionary. 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 ladder exists. Example 3 beginWord = "same" endWord = "same" wordList = ["same","came"] return = 1 The endpoints already match and the endpoint appears in the dictionary. Constraints 1 <= beginWord.length == endWord.length <= 10. 1 <= wordList.length <= 5000. Every dictionary word has the same length as beginWord. Words contain only lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Treat each word as a node and connect words that differ by one letter. Every edge has the same cost, so BFS from beginWord gives the shortest path, and you return the level count when you pop endWord. Don't compare every pair of words, that's 5000 squared times 10. Instead, for each word try all 10 positions and all 26 letters, then check membership in a hash set. That's about 260 lookups per word. Remove words from the set as you visit them so nothing is queued twice. The common pitfalls: forgetting that endWord must be in the dictionary (return 0 immediately if it isn't), counting edges instead of words, and missing the equal-endpoints case. Check that case first. If the timer is running and the BFS won't come together, StealthCoder can supply a working solution during the live OA, but you should be able to write this yourself.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Word Ladder 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
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 Amazon's OA.
Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Word Ladder FAQ
What's the trick in Amazon's Word Ladder?+
Model it as an unweighted graph and run BFS from beginWord. Neighbors are dictionary words one letter away. Generate them by swapping each position with a through z and checking a hash set. The first time you reach endWord, the level count is your answer.
Why not just use DFS or backtracking?+
DFS finds a path, not necessarily the shortest one. You'd have to explore many paths and compare them, which blows up with 5000 words. BFS explores by distance, so the first hit on endWord is guaranteed shortest and each word is processed once.
What edge cases does this version test?+
Three. If endWord isn't in wordList, return 0. If beginWord equals endWord, return 1 only when the word is in the dictionary. And beginWord itself doesn't need to be in the dictionary. Count words in the sequence, including both endpoints, not edges.
How fast does my solution need to be?+
Aim for roughly words times length times 26 operations, which is about 1.3 million set lookups at the max input. Pairwise comparison of all words is much heavier and risks timing out. Use a hash set for lookups and remove visited words so you never revisit them.
How do I prepare for this in 48 hours?+
Write BFS on a grid once, then write Word Ladder from scratch twice without notes. Focus on the neighbor generation loop and the level counter. Then test the three examples, especially the missing-endpoint and equal-endpoint cases. That covers nearly everything this problem can throw at you.