Probably best illustrated with a small example.
Given the relations
A < B < C
A < P < Q
Correct outputs would be
ABCPQ or APQBC or APBCQ ... etc.
In other words, any ordering is valid in which the given relationships hold.
I am most interested in the solution that is easiest to implement, but the best O(n) in speed and time is interesting as well.