Trains the technique from
LeetCode 126Word Ladder IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A relay station has to move from the call sign beginWord to the call sign endWord. All call signs are lowercase strings of the same length.
One hop rewrites exactly one letter of the current sign, and the sign it produces has to appear in the approved register wordList. A route is a list of signs that starts with beginWord, ends with endWord, and where each sign after the first is one hop from the sign before it. beginWord itself does not have to be in the register.
Return every route that uses the fewest hops possible, each route listed from beginWord to endWord. The routes themselves may come back in any order. Return an empty list when no route exists at all.
Example 1
Two routes of two hops each are the shortest ones: `fin` to `bin` to `ban`, and `fin` to `fan` to `ban`. Every sign in them comes from the register and every hop rewrites exactly one letter.
Example 2
`ten` is in the register and differs from `tin` in one letter, so a single hop is enough and only one route is that short.
Example 3
`oak` is in the register but shares no letter position with any sign that can be reached from `fin`, so no route ever arrives and the answer is empty.
The values you return may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_ladders(beginWord: str, endWord: str, wordList: list[str]) -> list[list[str]]:public List<List<String>> findLadders(String beginWord, String endWord, List<String> wordList)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.