Given a list of words, determine whether the words can be chained to form a circle. A word X can be placed in front of another word Y in a circle if the last character of X is same as the first character of Y. For example, the words ['chair', 'height', 'racket', touch', 'tunic'] can form the following circle: chair --> racket --> touch --> height --> tunic --> chair The output it has to be a txt file with one word per line, ex: chair racket touch height tunic Is very important the logic and the performance of the algorithm.
- Clone this repo and execute from console.
$ php challenge.php
- You can change filename output updating
FILENAME
constant. - At the top of script are differents datasets to test.
- Tested with more than 500000 words
- Same problem with alternative solutions here
Pablo Cerbino [email protected]