At each iteration, make all possible new words from the words that you have, and collect them in a list, set or whatever. Filter out duplicates and words that you had before. For instance:
1. (BED)
2. (BAD, BET, ....)
3. (MAD, BAN, ...., BUT, BOT, ....)
You either get an empty list, then the problem is not solvable, or the search word is in the list.
source
share