Find the Town Judge
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on Find the Town Judge is checking only one of the two conditions. Google candidates reported this one in October 2026, and it looks easy enough that people rush it. You get n people and a list of trust pairs. The judge trusts nobody and everybody else trusts them. It's a graph degree problem wearing a hash-table or array costume. If you've got an OA invite coming, know the trick cold. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is learnable tonight.
The problem
There are n people labeled from 1 through n. Each row trust[i] = [a, b] means that person a trusts person b. A person is the town judge when both conditions hold: The person trusts nobody. Every other person trusts that person. Return the judge's label. Return -1 when no person satisfies both conditions. When n = 1 and there are no trust relationships, person 1 is the judge. Examples Example 1 n = 2 trust = [[1,2]] return = 2 Person 2 trusts nobody and is trusted by the only other person.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is degree counting. Keep one array of size n+1. For each pair [a, b], decrement score[a] and increment score[b]. The judge is the person whose score equals n-1. That single number encodes both conditions: trusted by all n-1 others and trusting nobody, since any outgoing trust drops the score below n-1. The common pitfall is counting only incoming trust. Then someone who is trusted by everyone but also trusts another person passes wrongly. The second pitfall is the edge case n = 1 with empty trust, where person 1 is the judge and the score of 0 equals n-1. A loop that returns -1 early on empty input breaks it. Runtime is O(n + trust length) with O(n) space. If you blank during the live OA, StealthCoder can surface this scoring approach in real time, but writing it yourself takes five minutes.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Find the Town Judge 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 by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as find the town judge. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find the Town Judge FAQ
How hard is Find the Town Judge really?+
It's easy once you see the degree trick. The difficulty is in remembering both conditions and the n = 1 edge case. Most failures come from rushing and counting only incoming trust, not from algorithmic complexity.
What's the trick to solving it fast?+
Use one score array. Subtract one from the truster and add one to the trusted person for every pair. The judge ends with exactly n-1. That covers trusting nobody and being trusted by everyone else in a single check.
Which edge cases should I test before submitting?+
Test n = 1 with empty trust, which returns 1. Test a case where someone is trusted by all but also trusts someone, which returns -1. Test two people with no relationships. Also test a graph where two people look like candidates.
Is this graph pattern still asked in 2026?+
Google candidates reported it in October 2026, so yes. Degree counting on directed graphs shows up regularly in screens because it checks whether you can reduce two conditions into one clean invariant.
How do I prepare for this in 48 hours?+
Write the score-array solution from memory twice. Then solve it with separate in-degree and out-degree arrays to see why they match. Finish by running your edge cases by hand. That's enough for this problem and similar degree questions.