Problem · String
Word Ladder
Learn this problemProblem statement
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[]) → intExamples
Example 1
beginWord = "hit"endWord = "cog"wordList = ["hot","dot","dog","lot","log","cog"]return = 5A shortest sequence is hit -> hot -> dot -> dog -> cog.
Example 2
beginWord = "hit"endWord = "cog"wordList = ["hot","dot","dog","lot","log"]return = 0More Goldman Sachs problems
- Data ReorganizationSeen Jul 2026
- Inherited Role PermissionsONSITE INTERVIEW · Seen Jul 2026
- Root of the Largest TreePHONE SCREEN · Seen Jul 2026
- Validate Binary Search TreeONSITE INTERVIEW · Seen Jul 2026
- Alternating Parity PermutationsOA · Seen Jul 2026
- Threshold AlertsSeen Jul 2026
- Cheapest Flights Within K StopsONSITE INTERVIEW · Seen Jun 2026
- Log Buffer AnalyzerOA · Seen May 2026