Given a series of game results such as xxxx beats yyyy, output the final ranking.

Example 1:

Input: ["a beats b", "b beats c", "c beats d"]
Output: ["a", "b", "c", "d"]

Example 2:

Input: ["a beats b", "a beats c"]
Output: ["a", "b", "c"] or ["a", "c", "b"]

You can assume that there are no cycles.

Comments (7)