Find the Town Judge
Try to solve the Find the Town Judge problem.
We'll cover the following
Statement
There are n
people numbered from n
in a town. There's a rumor that one of these people is secretly the town judge. If there is a town judge, they must meet these conditions:
There are n
people numbered from n
in a town. There’s a rumor that one of these people is secretly the town judge. A town judge must meet the following conditions:
The judge doesn’t trust anyone.
Everyone else (except the judge) trusts the judge.
Only one person in the town can meet both of these conditions.
Given there is n
and a two-dimensional array called trust
, each element trust[i]
has two elements a
trusts person b
. If there is a judge, return their number, return
Constraints:
n
trust.length
trust[i].length
a
i
b
i
a
i
,b
i
n
All the pairs inÂ
trust
 are unique.
Examples
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.