Count Determinable Player Rankings
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that breaks the naive solution in this Google OA, reported in September 2026, is the contradictory cycle. Most people compute reachability, count known pairs, and ship it. Then example 4 fails. The problem is a transitive closure on a directed graph with n up to 300, and the twist is that mutual reachability disqualifies a pair instead of counting twice. If you blank on the closure step during the live assessment, StealthCoder runs invisibly as a safety net and gives you a working solution while you keep your head. Read the cycle rule twice before you write anything.
The problem
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[][]) → int Examples Example 1 n = 3 wins = [[0,1],[1,2]] return = 3 Transitivity establishes 0 > 1 > 2, so every player's relation to both others is known in exactly one direction. Example 2 n = 4 wins = [[0,1],[0,2],[1,3],[2,3]] return = 2 Player 0 is above everyone and player 3 is below everyone. Players 1 and 2 are incomparable. Example 3 n = 3 wins = [[0,1]] return = 0 Every player has at least one unknown relation involving player 2. Example 4 n = 3 wins = [[0,1],[1,0],[1,2]] return = 1 Players 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 wins contains 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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build a reachability matrix from the wins edges, then run Floyd-Warshall style closure: for k, i, j, reach[i][j] |= reach[i][k] && reach[k][j]. With n at 300 that's about 27 million operations, which is fine. Bitsets or a DFS from each node also work. Then, for each player i, check every other player j. The pair is good only if exactly one of reach[i][j] and reach[j][i] is true. If both are true, it's a cycle and the player fails. If neither is true, they're incomparable and the player fails. Count players who pass against all others. The common pitfall is using OR instead of XOR, which lets cycle members slip through. Another one is forgetting that duplicate edges are harmless. Example 4 is your test: players 0 and 1 must both fail, and player 2 must pass. If you freeze on the closure code during the live OA, StealthCoder is the hedge.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Count Determinable Player Rankings cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Determinable Player Rankings FAQ
What's the trick in Count Determinable Player Rankings?+
Compute the transitive closure, then require exactly one direction of reachability for every other player. That's an XOR check per pair. Both directions means a cycle and the pair fails. Neither direction means incomparable and it also fails.
How hard is this one really?+
Medium. The closure is standard, but the cycle rule trips people up. If you treat 'both reachable' as fine, example 4 returns the wrong answer. Once you see the XOR condition, the code is about 20 lines.
Will Floyd-Warshall be fast enough with n = 300?+
Yes. It's O(n^3), about 27 million simple boolean operations. That runs fast in any mainstream language. You can also run a DFS or BFS from each node for O(n * (n + e)), which is similar at this size.
How do I handle duplicate edges and self-pairs?+
Duplicates just set the same matrix cell to true again, so they change nothing. Rows always have distinct players, so no self-loops in the input. When you check pairs, skip j equal to i. Note that a cycle can make reach[i][i] true after closure, so ignore the diagonal.
How do I prepare for this in 48 hours?+
Write the closure once from memory, then run all four examples by hand. Focus on example 4 and example 3, since they cover the cycle and the incomparable cases. Practice the per-player loop that checks every other player and exits early on the first bad pair.