Skip to content

Commit

Permalink
Solution to #10
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatr21 committed May 10, 2020
1 parent 371f9d0 commit 1e11884
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Solutions/S10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
int findJudge(int N, vector<vector<int>>& trust) {
unordered_map<int, int> truster, trusted;
for(int i = 0; i < trust.size(); i++)
{
//Let trust[i][0] = Person a and trust[i][1] = Person b
//truster -> No of persons whom person a trusts
//trusted -> No of persons trusting person b
truster[trust[i][0]]++;
trusted[trust[i][1]]++;
}
for(int i = 1; i <= N; i++)
{
//Definition of town judge, trusts nobody and trusted by everyone
if(truster[i] == 0 && trusted[i] == N - 1) return i;
}
return -1;
}

0 comments on commit 1e11884

Please sign in to comment.