Question: In a given start string, end string and a set of strings, find if there exists a path between the start string and end string
In a given start string, end string and a set of strings, find if there exists a path between the start string and end string via the set of strings.
A path exists if we can get from start string to end the string by changing
(no addition/removal) only one character at a time. The restriction is that the new string generated after changing one character has to be in the set.
Start: "cog" End: "bad" Set: ["bag", "cag", "cat", "fag", "con", "rat", "sat", "fog"] One of the paths: "cog" -> "fog" -> "fag" -> "bag" -> "bad"
Step by Step Solution
There are 3 Steps involved in it
We need to determine if theres a path between a given start node and end node Solution Approach BreadthFirst Search BFS BFS is an algorithm that explores nodes layer by layer Its suitable for this pro... View full answer
Get step-by-step solutions from verified subject matter experts
