Fixed Ranks
Asked at Google
Reported by the problem's creator, not verified
There are n players numbered 0 to n - 1. Each game result is a [winner, loser] pair meaning the winner ranks strictly better than the loser, with rank 0 the best. Better-than carries over: if a beat b and b beat c, then a ranks better than c even if they never played.
Examples
Example 1
Input: n =
5, game_results =[[0,1],[1,2],[2,3],[2,4],[3,4]]Output:
[[0,0],[1,1],[2,2],[3,3],[4,4]]Explanation: The results form a chain 0, 1, 2, 3, 4 (2 beats 4 is implied by 2 beats 3 beats 4), so every player is comparable with every other and each player's rank equals the number of players above them in the chain.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.