The Find the Town Judge interview question is a graph-based identification task. In a town of people, there is a rumor that one person is the "town judge." The judge is defined by two properties: they trust nobody, and everyone else trusts them. You are given an array of trust relationships [a, b], where trusts . Your goal is to find the town judge if they exist, or return -1 otherwise.
Companies like Microsoft and Google use the Find the Town Judge coding problem to test a candidate's ability to model relationships using Graph interview patterns. It evaluates whether you can use in-degrees and out-degrees to identify specific nodes in a directed graph. It’s an excellent problem for demonstrating how to use frequency arrays instead of complex adjacency lists.
This problem follows the In-degree and Out-degree counting pattern.
trust_scores of size .
[a, b], decrement trust_scores[a] and increment trust_scores[b].Town size , Trust: [[1, 3], [2, 3]].
trust_scores[1] = -1, trust_scores[3] = 1.trust_scores[2] = -1, trust_scores[3] = 2.Map<Integer, List<Integer>> which is overkill and less efficient than a simple score array.Always look for the most compact way to represent node properties. If you only care about "how many" edges go in and out, a single array or two counters is often better than a full graph data structure. This is a core Hash Table interview pattern optimization.