← Questions
Recommend accounts your followees follow
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Meta's AI-enabled coding round, last asked Aug 2025. It tests python, graphs and hash maps.
A follow graph is given as a dictionary from each user to the list of people they follow. For a user U, recommend everyone followed by the people U follows, leaving out U and anyone U already follows.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
recommend(graph: dict[str, list[str]], user: str) -> list[str]— the recommendations without duplicates, sorted alphabetically so the output is deterministic. A user who is not a key follows nobody.
Example
graph = {"A": ["B", "C"], "B": ["C", "D"], "C": ["E"]}
recommend(graph, "A") -> ["D", "E"] # C is excluded: A already follows C
recommend(graph, "B") -> ["E"] # D follows nobody
recommend(graph, "E") -> [] # E follows nobody
Constraints
- Up to
10^5users and10^6follow edges. - Self-follows and mutual follows may appear.
Clarifying questions
- Is the graph directed (follows) or undirected (friendships)?
- Should the result be ranked, and by what?
- Can a user appear only as a followee and never as a key?
- Is the user themselves ever in the candidates? (Yes, through a mutual follow; exclude them.)
What a strong answer covers
- A set of
U's direct follows for O(1) checks, a loop over each followee's follows, and a result set that removesU, direct follows and duplicates. - O(sum of the followees' out-degrees) time and O(candidates) space.
- Using
graph.get(v, [])for users with no entry, and deduplicating repeated edges. - Tests: an unknown user, mutual follows, self-follows, a followee with no entry.
Follow-ups
- Rank the recommendations by how many of
U's followees follow each one. With{"A": ["B", "C", "D"], "B": ["E", "A"], "C": ["E", "F"], "D": ["E", "B"]}, userAgetsE(3 followees) beforeF(1). - Return only the top
kfor users who follow thousands of people. - Compute recommendations for every user at once on a graph too large for one machine.
Where it's asked
- Meta · AI-enabled coding · Last asked Aug 202560 min · Several progressive tasks on a starter codebase in CoderPad with an AI assistant panel; usually two rounds · The first task usually without AI, later tasks with it
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
