Word Ladder II
Updated
Problem statement
Given two distinct lowercase words beginWord and endWord, and an array wordList of distinct lowercase words of the same length, return every shortest transformation sequence from beginWord to endWord.
In one transformation, change exactly one character. Every word after beginWord, including endWord, must appear in wordList. If no sequence exists, return an empty array.
Sort the returned sequences lexicographically by their complete word sequence.
Function
findLadders(beginWord: String, endWord: String, wordList: List<String>) → List<List<String>>Examples
Example 1
beginWord = "hit"endWord = "cog"wordList = ["hot","dot","dog","lot","log","cog"]return = [["hit","hot","dot","dog","cog"],["hit","hot","lot","log","cog"]]Both sequences use four transformations, and no shorter path reaches cog.
Example 2
beginWord = "hit"endWord = "cog"wordList = ["hot","dot","dog","lot","log"]return = []The required end word is absent from wordList, so no valid sequence exists.
Example 3
beginWord = "a"endWord = "c"wordList = ["a","b","c"]return = [["a","c"]]The one-character words differ in exactly one position, so the direct transformation is shortest.
Constraints
1 <= beginWord.length == endWord.length <= 101 <= wordList.length <= 500- All words contain only lowercase English letters and have the same length.
- All words in
wordListare distinct. beginWord != endWord.- The total returned output contains at most
10000words.
More Bloomberg LP Phone Screen questions
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Word LadderGoogle · ONSITE INTERVIEWGoogle interview questions
- Find Duplicate Files in a FilesystemHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Shortest Word Transformation SequenceReddit · PHONE SCREENReddit interview questions
- Word LadderGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Word Ladder II: All Shortest TransformationsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Word LadderMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Find Minimum City HopsAmazon · OA
- Shortest Path from Encoded Graph EdgesBitGo · OABitGo interview questions
- Bus RoutesUiPath · PHONE SCREEN
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)