I was playing the game Word Snake and I was wandering if it is be possible to solve this game using an algorithm.
Here is the description of the game:
Given a bag (a set with possible repeating values) of phrases: S = {phrase1, phrase2, phrase3, ..., phraseN}
A snake is an ordered list of phrases from S such that, except for the first phrase, the first word in the phrase matches the last word in the previous phrase. Also, the phrasei (where 1 ≤ i ≤ N) can only be present once.
How to find the maximum length of all possible snakes?
Example: For S = { 'A B' , 'B C' , 'B D' , 'C B' , 'C D'}, the maximum length would be 4 because ['A B', 'B C', 'C B', 'B D'] is the longest snake.