Show Strings With Last Characters of the first Word

Hello There Senior Programmer of Unity3d…
Can i ask u something about how to show 5 Words just like : Apple, Electro, Organic, Champ, and Pen
First i want to show words “Apple” and following by “Electro” and “Organic” and etc
but the first words “Apple” must be showed first and then the second words is taken from last character of the first Word “Apple → E” and the Second character show up “Electro” and etc
Example: 1. ApplE
2. ElectrO
3. OrganiC
4. ChamP
5. Pen

Could u help me to solve this problem? sorry for bothering u all with some questions like this…

Best Regards,
Hadi From indonesia

Query, does your algorithm need to find the best path through the words? Or just a path?

To find any path:

  • Put all the unused words in an unused list
  • Grab a random word, remove it from the list and add it to a used list
  • Search the unused list for a word where the first letter (The string class has several methods that will help. You can also convert the string to a character array)
  • Remove the found word the unused list and add it to the used list
  • Repeat

You will have to define your behaviour once a match cannot be found.

To find the best possible path

  • Build a directed graph by linking each word to the possible follow on words
  • Starting from each node traverse the graph until a path is found which includes all nodes

There is a bunch of optimisations in graph theory that may be able to help. Consider first splitting the graph up into multiple sub graphs by checking for nodes that are impossible to reach. Also consider marking nodes that must be at the end or start of a chain. There may be some similarities to algorithms for finding the critical path.