Graph Theory37 sections · 1633 units
Open in Course

Problem Time - Town Judge

LeetCode 997

You'll solve your first graph problem. Problem: Find the Town Judge This problem tests your understanding of directed degrees. Someone is the judge only if everyone else trusts them (high in-degree) and they trust nobody (zero out-degree).

You will translate this observation into code using degree counting. No fancy algorithm needed, track in-degrees and out-degrees for each person. If exactly one person has in-degree n1n-1 and out-degree 00, that person is the judge.