This question already has an answer here:

Given a list/array of names(String) sort them such that each name is followed by a name which starts with the last character of the previous name.


[ Luis Hector Selena Emmanuel Amish ]


[ Emmanuel Luis Selena Amish Hector ]


marked as duplicate by Howard, Victor Stafusa, Doorknob, Timtech, Dr. belisarius Jan 7 '14 at 22:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    \$\begingroup\$ What do we output if it's not possible with the given list? What about if there is more than one possible solution? \$\endgroup\$ – Gareth Jan 7 '14 at 20:35
  • 1
    \$\begingroup\$ Why is this Java-specific? \$\endgroup\$ – Kendall Frey Jan 7 '14 at 20:35
  • \$\begingroup\$ What's your objective winning criterion? Shortest code, most upvotes, or something else? \$\endgroup\$ – Kendall Frey Jan 7 '14 at 20:36
  • \$\begingroup\$ Sorry for tagging it as java problem. @Kendall Frey Objective is to get a solution, and may be optimize it further. \$\endgroup\$ – high-voltage Jan 8 '14 at 9:02
  • \$\begingroup\$ @Gareth A solution will always exist for the given input. \$\endgroup\$ – high-voltage Jan 8 '14 at 9:05

Browse other questions tagged or ask your own question.