Count Determinable Player Rankings
Updated
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.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Minimum Completion Time for DAG DependenciesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Minimum Time to Complete Target CoursesMeta · ONSITE INTERVIEWMeta interview questions
- Cheapest Flights Within K StopsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Critical Path Through Dependent TasksModular · PHONE SCREEN · ONSITE INTERVIEW
- Rocket Component CostSpaceX · ONSITE INTERVIEWSpaceX interview questions
- Knight Dialer SequencesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- All-Pairs Shortest PathsMorgan Stanley · OA · ONSITE INTERVIEWMorgan Stanley interview questions
- Distance Sums to Special Nodes in a Weighted TreeNutanix · ONSITE INTERVIEWNutanix interview questions
- Knight Dialer SequencesConfluent · ONSITE INTERVIEWConfluent interview questions
- Parallel Courses IIISnowflake · ONSITE INTERVIEWSnowflake interview questions