Find the Town Judge 🚞

  1. The town judge trusts nobody.
  2. Everybody (except for the town judge) trusts the town judge.
  3. There is exactly one person that satisfies properties 1 and 2.
Input: n = 2, trust = [[1,2]]
Output: 2
Input: n = 3, trust = [[1,3],[2,3]]
Output: 3
Input: n = 3, trust = [[1,3],[2,3],[3,1]]
Output: -1
  • 1 <= n <= 1000
  • 0 <= trust.length <= 104
  • trust[i].length == 2
  • All the pairs of trust are unique.
  • ai != bi
  • 1 <= ai, bi <= n

Solution

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

React or Angular? The Frontend for the Future

JSP and Servlet in Java

Permutations🏈

An Introduction to Stimulus.js

Make a dash-ing project — 2

Upgrading main JavaScript libraries inside a Mono-Repository

Getting Started with P5.js in VScode

JavaScript’s reduce method. A Powerful Ally

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tehleel Mir 🐢

Tehleel Mir 🐢

More from Medium

Missing Number 🍀

Intuitive recursion

Leetcode 1 — Two Sum