Question
Implement a function bool chainable(vector
, which takes a set of strings as parameters and returns true
if they
if you replace petal
and lion
with pawn
and label
, you still have:
starts:s,p,l,n
ends: p,l,n,k
You're algorithm decides its chainable, but they aren't.
The problem is you are disconnecting the first and last letters of each word.
A recursive backtracking or dynamic programming algorithm should solve this problem.