Question
Implement a function bool chainable(vector
, which takes a set of strings as parameters and returns true
if they
Here's a case where your algorithm doesn't work:
ship
pass
lion
nail
Your start and end lists are both s, p, l, n
, but you can't make a single chain (you get two chains - ship->pass
and lion->nail
).
A recursive search is probably going to be best - pick a starting word (1), and, for each word that can follow it (2), try to solve the smaller problem of creating a chain starting with (2) that contains all of the words except (1).