Understand the problem
Restate the problem precisely. Interviewers reward candidates who pause, define the contract, and name the guarantees before coding.
In a town, there are `n` people labeled from `1` to `n`. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then the town judge trusts nobody, everybody (except for the town judge) trusts the town judge, and there is exactly one person that satisfies properties 1 and 2. You are given an array `trust` where `trust[i] = [aᵢ, bᵢ]` representing that the person labeled `aᵢ` trusts the person labeled `bᵢ`. If a trust relationship does not exist in `trust` array, then such a trust relationship does not exist. Return the label of the town judge if the town judge exists and can be identified, or return `-1` otherwise.
Once you've drafted a response, click Submit for AI review and a senior engineer will critique your reasoning.