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.
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample Answer
Requirements
- Input:
nandtrustlist 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...