Description

In a town, there is exactly one judge. The judge trusts nobody, but everybody trusts the judge. Given trust relationships, find the judge or return -1.

Examples

Input:n = 2, trust = [[1,2]]
Output:2
Explanation:

Person 2 is trusted by 1.

Input:n = 4, trust = [[1,4],[2,4],[3,4]]
Output:4
Explanation:

Person 4 is trusted by persons 1, 2, and 3 (everyone else), and person 4 trusts nobody. Therefore, person 4 is the town judge.

Input:n = 1, trust = []
Output:1
Explanation:

With only one person in the town and no trust relationships, person 1 is automatically the judge since they trust nobody and are trusted by everyone (vacuously true as there's nobody else).

Constraints

  • 1 ≤ n ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!