Identify the One Account Trusted by Every Other Account

Last updated: November 29, 2026

Quick Overview

There are n accounts labeled 1 to n and a list of directed trust pairs (a, b) meaning a trusts b. Find the account that trusts nobody and is trusted by all other n-1 accounts, or return -1 if none exists.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


There are n accounts labeled 1 to n and a list of directed trust pairs (a, b) meaning a trusts b. Find the account that trusts nobody and is trusted by all other n-1 accounts, or return -1 if none exists.

An online assessment style warm-up that models a sharing graph, for example finding a single admin account in a Google Workspace domain that everyone delegates to. It tests whether you see that in-degree and out-degree counts solve it without any traversal.

What the Interviewer Expects
  • Model trust as a directed graph
  • Track in-degree minus out-degree per node
  • Recognize that at most one such account can exist
  • Handle n equals 1 with no pairs
  • Give O(n + m) time with O(n) space
Key Topics to Cover
directed graph
in-degree
out-degree
celebrity problem
counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Can you solve it with only a has_trust(a, b) API and O(n) calls?
  • What if trust pairs contain duplicates?
  • How would you find all accounts trusted by at least k others?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: n and trust list of (a, b).
  • Target: out-degree 0 and in-degree n - 1.
  • Return its label or -1.
  • Assume pairs are unique (ask; duplicates would break pure counting)....
High-Level Design

No traversal needed. Keep one score per account: add 1 for each incoming trust, subtract 1 for each outgoing trust. The target is the only account whose score can reach exactly n - 1, because reachi...


Submit Your Answer
Markdown supported