Word Ladder
Reported by candidates from Goldman Sachs's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Goldman Sachs reported this Word Ladder OA in July 2026, and the first thing to check is the size of wordList. Trying every permutation of transformations explodes fast, so brute force is dead on arrival. This is a shortest-path problem in disguise: words are nodes, one-letter changes are edges, and BFS gives you the answer. If you've seen it before, you'll finish quickly. If you blank on how to build the edges without comparing every pair, StealthCoder is the invisible safety net running during the live OA. Know the BFS shape before you open the assessment.
The problem
Given beginWord, endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord. Every transformation changes exactly one letter, and every transformed word, including endWord, must be in the dictionary. Return 0 when no 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 A shortest sequence is hit -> hot -> dot -> dog -> cog. Example 2 beginWord = "hit" endWord = "cog" wordList = ["hot","dot","dog","lot","log"] return = 0
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is BFS from beginWord, since every edge has equal weight and BFS finds the shortest path first. Put the wordList in a set for O(1) lookups. For each word you pop, try swapping each position with 'a' through 'z', and if the new word is in the set, push it with level plus one and remove it from the set so you never revisit it. Return the level when you hit endWord. The common pitfalls: forgetting that endWord must be in the list (return 0 right away if it isn't), counting edges instead of words (the answer includes beginWord, so start at 1), and comparing all pairs of words, which is O(n^2 * L) and times out. The neighbor generation is O(26 * L) per word. If you freeze mid-assessment, StealthCoder can supply the BFS template while you stay in control of the submission.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
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 Goldman Sachs's OA.
Goldman Sachs reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Word Ladder FAQ
What's the trick to Word Ladder?+
Treat it as an unweighted graph and run BFS from beginWord. Generate neighbors by swapping each character with a-z and checking a hash set. BFS guarantees the first time you reach endWord is the shortest path, so you return the level count immediately.
Why does brute force fail here?+
Comparing every pair of words to find one-letter differences costs O(n^2 * L), and trying all transformation sequences is exponential. Generating 26 * L candidates per word and checking a set keeps it near O(n * 26 * L), which fits large dictionaries.
Should I use DFS or BFS?+
BFS. DFS can find a path but not necessarily the shortest one, and you'd have to explore all paths to be sure. BFS explores level by level, so the first hit on endWord is optimal. Use a queue and a visited set.
What edge cases should I test?+
If endWord isn't in wordList, return 0. If beginWord equals endWord, check how the problem counts. Also test a dictionary with no connecting path, like Example 2. Remember the answer counts words, so beginWord counts as 1.
How do I prepare for this in 48 hours?+
Write the BFS solution from scratch twice without looking. Focus on the neighbor generation loop and marking words visited on enqueue. Then do two other grid or graph BFS problems to keep the queue pattern fresh. That's enough for a problem like this.