I'll show you how to find the town judge using degree counting. The judge must be trusted by everyone, so in-degree equals . The judge trusts nobody, so out-degree equals .
You loop through all people and check if anyone satisfies both conditions. If yes, return that person. If no, return .
Time complexity: where is the number of trust pairs. Space complexity: for the degree arrays.