Trains the technique from
LeetCode 997Find the Town JudgeThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A hall holds n people numbered 1 through n. Each entry trusts[i] = [a, b] says person a trusts person b, and no entry is listed twice.
The steward is the one person who trusts nobody at all and whom every other person trusts.
Return the steward's number, or -1 when there is none.
Example 1
With one person in the hall, that person trusts nobody and there is nobody left who has to trust them, so they are the steward.
Example 2
Person 3 trusts nobody, and the other three all trust them, which is exactly what the steward has to be.
Example 3
Each person trusts the other, so neither trusts nobody and there is no steward.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def find_judge(n: int, trusts: list[list[int]]) -> int:public int findJudge(int n, int[][] trusts)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.