Problem 45463. Word Ladder
Given a set of words, and two other words - start and destination,
Find the smallest chain from start to the destination such that adjacent words in the chain only differ by one character and each word in the chain exists in the set.
All the words are of the same length. The starting word is not in the set but destination word would be.
For example,
Start = 'COLD' Destination = 'WARM' set ={ CORD CARD DART FORT WARM FARM WARD}
COLD → CORD → CARD → WARD → WARM
Solution Stats
Problem Comments
-
2 Comments
Hi Asif Newaz,
thx for the problem. I enjoyed to solve it. But in the task i found a missing information. Second Test case provides in the set follwing words 'can','fan','pat'.
In the second iteration when function found pan, all three cases match and i do not see any rule in the description, why it has to be pat. When i follow in the Test Cases the solution, it seems words which differ a single character only at the end of the pattern will get preferred. For my understanding, the current description is not limiting any solution when multiple Hits are detected.
Maybe add an additional requirement, clarifying the rank of matches.
Thx :-).
Multiple solutions may exist for this problem, but the test suite only considers one correct. For instance, in test #2, y = {'mat' 'pat' 'put' 'aut' 'apt' 'ape'}; is a valid path from the word man to the word ape. This means we must use words in the order we find them as a priority queue.
Solution Comments
Show commentsProblem Recent Solvers10
Suggested Problems
-
Return a list sorted by number of occurrences
2778 Solvers
-
Extract leading non-zero digit
2135 Solvers
-
860 Solvers
-
Project Euler: Problem 7, Nth prime
1428 Solvers
-
108 Solvers
More from this Author165
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!