FastPrepWord Ladder
Problems/Word Ladder

Word Ladder

Goldman Sachs logoGoldman Sachs● HardFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem is backed by a real Goldman Sachs CoderPad interview report. The report directly named Word Ladder, but it did not include the exact function interface, examples, constraints, or whether the requested output was a length or the sequence itself. This judged version uses the shortest-length form, so the core task match is about 85%.

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: List<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

Constraints

  • 1 <= beginWord.length <= 10.
  • endWord.length == beginWord.length.
  • 1 <= wordList.length <= 5000.
  • wordList[i].length == beginWord.length.
  • beginWord, endWord and wordList[i] consist of lowercase English letters.
  • beginWord != endWord.
  • All the words in wordList are unique.

More Goldman Sachs problems

  • House Robber IIIPHONE SCREEN · Seen Nov 2026
  • Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · Seen Nov 2026
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public int ladderLength(String beginWord, String endWord, List<String> wordList) {
      // write your code here
    }
}
Checking account…