Loading
Loading
In a word game, players turn start into goal by changing exactly one letter per move. Every word produced along the way, including goal itself, must appear in the allowed list words. The starting word does not need to be in the list.
Return the number of words in the shortest chain, counting both start and goal. If no chain exists, return 0. If start already equals goal and goal is allowed, the chain is just that one word.
start = "cold", goal = "warm", words = ["cord","card","ward","warm","worm","word","wore"]cold1cord2 — change l to rcard3 — change o to award4 — change c to wwarm5 — change d to m5Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(words × L²) time · O(words × L²) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Example 2
No allowed word sits one letter away from "fame" on the way to "fire", so no chain exists.
Example 3