Find the Town Judge
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A town has n people labelled 1 to n. You are given a list trust where trust[i] = [a, b] means person a trusts person b. Each pair appears at most once and nobody trusts themselves.
The town judge, if one exists, is a person who trusts nobody and is trusted by every other person. There can be at most one such person.
Return the judge's label, or -1 if no one satisfies both conditions.
Examples
Constraints
- 1 <= n <= 1000
- 0 <= trust.length <= 10^4
- trust[i].length == 2
- 1 <= a, b <= n and a != b
- All pairs in trust are distinct
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.