InferenceAI

Enter at least two characters to search.

Start free

Find the Town Judge

easyGraphs15 min10 XP

People are labelled 1 to n. Each [a, b] in trust means person a trusts person b. The judge trusts nobody and is trusted by everyone else. Return the judge's label, or -1.

Examples

EXAMPLE WALKTHROUGHtwo people

A guided view of the published example, not a trace of your code.

INPUT[2,[[1,2]]]
TASKtown_judge()
EXPECTED OUTPUT2

Start with the input values shown in this example.

Example 1 of 3

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

Output: 2

Explanation: two people

Input: n = 3, trust = [[1,3],[2,3]]

Output: 3

Explanation: three people

Input: n = 3, trust = [[1,3],[2,3],[3,1]]

Output: -1

Explanation: judge trusts someone

Hint 1

Track in-degree minus out-degree; the judge has a score of n - 1.

Topics

DSAGraphsPython