phrases. Each phrase is made of words in lowercase English letters separated by single spaces, with no leading or trailing spaces.
Two phrases can be glued together when the last word of the first one equals the first word of the second: the shared word is written once, so "green tea" and "tea party" become "green tea party".
Try every ordered pair of phrases with different indices i and j (order matters: gluing i to j and j to i are separate options) and return all distinct glued phrases sorted lexicographically.phrases=['green tea', 'tea party', 'party time', 'big green'] → ['big green tea', 'green tea party', 'tea party time']
"green tea" ends with tea and "tea party" starts with it, giving "green tea party". In the same way "tea party" + "party time" and "big green" + "green tea" are glued.
phrases=['go', 'go', 'stop'] → ['go']
The two separate "go" phrases glue into "go" (the shared word is written once) in both orders, but the answer lists it only once.
phrases=['sun rises', 'moon sets'] → []
No phrase starts with the last word of another, so the answer is empty.
len(phrases) ≤ 100len(phrases[i]) ≤ 100phrases[i] consists of lowercase English letters and single spaces, with no spaces at either endphrases=['green tea', 'tea party', 'party time', 'big green']
['big green tea', 'green tea party', 'tea party time']
Run checks the first 3 tests in your browser. Submit checks all 68 tests on the server, hidden ones included.