Count Determinable Player Rankings
Problem statement
There are n players labeled from 0 through n - 1. Each row wins[i] = [winner, loser] records that winner defeated loser.
Results are transitive: if player A defeated player B, and player B defeated player C, then A ranks above C.
A player's strict rank is determinable when, for every other player, exactly one of these facts is inferable:
- The player ranks above the other player.
- The other player ranks above the player.
If both directions are reachable because of a contradictory cycle, that pair does not establish a strict ordering. Return the number of players whose strict rank is determinable.
Function
countDeterminablePlayers(n: int, wins: int[][]) → intExamples
Example 1
n = 3wins = [[0,1],[1,2]]return = 3Transitivity establishes 0 > 1 > 2, so every player's relation to both others is known in exactly one direction.
Example 2
n = 4wins = [[0,1],[0,2],[1,3],[2,3]]return = 2Player 0 is above everyone and player 3 is below everyone. Players 1 and 2 are incomparable.
Example 3
n = 3wins = [[0,1]]return = 0Every player has at least one unknown relation involving player 2.
Example 4
n = 3wins = [[0,1],[1,0],[1,2]]return = 1Players 0 and 1 form a contradictory cycle, so neither has a strict rank. Player 2 is below both and is determinable.
Constraints
1 <= n <= 300.0 <= wins.length <= n * (n - 1).- Every row in
winscontains two valid, distinct player indices. - The same directed result may appear more than once and has the same effect as one occurrence.
- Contradictory cycles may occur.