lot dot dog logThis is not the shortest word-ladder between 'lot' and 'log' since the former can be immediately changed to the latter yielding a word ladder of length two:
lot logThe first and last words in a word ladder are the anchor rungs of the ladder. Any other words are interior rungs. For example, there are three interior rungs in the ladder below between 'smile' and 'evote'.
smile smite smote emote evoteIn this problem you'll write a method that has parameters representing potential interior rungs: a vector of strings (these by nonsense or English words), and the anchor rungs --- two strings. Your code must determine whether there exists any ladder between the exterior rungs that uses at least one interior rung. If there is any ladder the method returns "ladder", otherwise it should return "none".
const tvector<string>&
const string&, const string&
string
string ladderExists(const tvector<string>& words,
const string& from, const string& to);
(be sure your method is public)
[hot, dot, dog] hit cogReturns "ladder"
The only ladder is hit hot dot dog cog which has length five.
[hot, dot, dog, lot, log] hit cogReturns "ladder"
Now there are two length-five ladders:
hit hot dot dog cog hit hot lot log cog
[rain, ruin, gain, grin, grit, main, pain, pair, pail, mail] sail ruipReturns "ladder"
There are two ladders of length six and no shorter ladders.
sail mail main rain ruin ruip sail pail pain rain ruin ruip
[most, mist, fist, fish,] lost costReturns: "ladder"
Although lost is directly connected to cost, a valid word ladder must contain an interior rung so the shortest ladder is
lost most cost
[mist, fist, fish,] lost costReturns: "none"
Although lost is directly connected to cost, a valid word ladder must contain an interior rung so there is no valid ladder.