Practice Find the Town Judge
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
People are labeled 1 through n, and trust[i] = [a, b] means person a trusts person b. The judge must trust nobody and be trusted by every other person. Return the label of the unique person satisfying both conditions, or -1 if no such person exists. A relationship absent from trust does not exist.
Source: Find the Town Judge on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
n = 2, trust = [[1,2]]
Output
2
# Example 2
Input
n = 3, trust = [[1,3],[2,3]]
Output
3
# Example 3
Input
n = 3, trust = [[1,3],[2,3],[3,1]]
Output
-1
Constraints
1 <= n <= 1000
0 <= trust.length <= 10^4
trust[i].length == 2
All the pairs of trust are unique.
ai != bi
1 <= ai, bi <= n
Related LeetCode Problems
Practice more problems similar to Find the Town Judge.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.