A town has n people labeled 1 to n, and one of them may secretly be the town judge. The judge trusts nobody, everybody else trusts the judge, and exactly one person fits both rules. Given trust, where trust[i] = [a, b] means person a trusts person b, return the judge's label, or -1 if there is no judge.
A town has n people labeled 1 to n, and one of them may secretly be the town judge. The judge trusts nobody, everybody else trusts the judge, and exactly one person fits both rules. Given trust, where trust[i] = [a, b] means person a trusts person b, return the judge's label, or -1 if there is no judge.
Example 1:
Input: {"n":2,"trust":[[1,2]]}
Output: 2
Constraints:
1≤n≤1000
0≤trust.length≤104
trust[i].length==2
All the pairs of trust are unique.
ai=bi
1≤ai,bi≤n
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":2,"trust":[[1,2]]}
2 people and 1 trust pair. Each score starts at 0: trusting someone costs 1, being trusted earns 1.