15% off all plans & roadmaps Use code
See plansProblem editorial
There are n people, identified by the integers from 1 through n. Each inner array in trust has the form [a, b], meaning person a trusts person b.
Find the Town Judge is a Array/Matrix Manipulation Patterns problem, in the Hashing - Frequency Map / Counting subpattern. The pattern covers in-place operations, hashing, prefix sums, spiral traversal, and cyclic sort
The reference solution runs in O(n + trust.length) time and O(n) space.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Find the Town Judge is a Array/Matrix Manipulation Patterns problem, in the Hashing - Frequency Map / Counting subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.