← Google Interview Insights

Google·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Google MLE coding round, one graph problem with a follow-up that actually made things interesting. Pretty standard overall but the follow-up caught me off guard in a good way.

Questions Asked (1)

Q1

Given a social network, find all friends of a given user. Follow-up: how would your solution change if users can also unfriend each other?

Algorithms & Data StructuresSystem Design
Author's notes

The base problem was a graph traversal thing, BFS to find connected nodes.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: model the social network as a graph where users are nodes and friendships are edges. For the basic case, represent friendships as an adjacency list and simply return the list of neighbors for the given user. For the follow-up, discuss how to handle deletions efficiently, considering data structures like hash sets for O(1) removals and the trade-offs between adjacency lists and matrices.

Pro tip: Demonstrate awareness of real-world constraints: mention that in a large-scale system like Google's, you'd likely use a distributed graph store or a sharded adjacency list, and discuss consistency models for unfriending (e.g., eventual vs. strong consistency).

1. Clarify requirements and assumptions

Ask whether the graph is directed or undirected, whether friendships are mutual, and what the expected scale is (number of users, average friends). Clarify if the friend list needs to be sorted or if any order is acceptable.

2. Choose data representation

For the basic case, propose an adjacency list (e.g., hash map from user ID to a list/set of friend IDs) as it's space-efficient for sparse graphs. Mention that an adjacency matrix is possible but inefficient for large, sparse networks.

3. Implement friend retrieval

Describe the algorithm: look up the user in the hash map and return the associated collection of friends. Analyze time complexity: O(1) average lookup plus O(d) to return the list, where d is the degree (number of friends).

4. Address the follow-up: unfriending

Explain that with an adjacency list using sets for friend lists, unfriending is O(1) on average: remove each user from the other's set. Discuss the need to update both sides if friendships are mutual, and consider concurrency issues in a distributed setting.

5. Discuss scalability and trade-offs

Mention that for a massive social network, a single machine may not suffice; propose sharding by user ID, using a distributed graph database, or caching friend lists. Discuss trade-offs between read and write performance, and consistency models for unfriending.

Key Points to Mention

  • Graph representation: adjacency list vs. adjacency matrix, and why adjacency list is preferred for sparse social networks.
  • Time complexity: O(1) average for lookup and O(d) for returning friends; unfriending in O(1) with hash sets.
  • Space complexity: O(V + E) for adjacency list, where V is users and E is friendships.
  • Handling unfriending: need to remove edges from both users' lists if friendships are mutual; use sets for efficient deletion.
  • Scalability: sharding, distributed graph stores (e.g., Bigtable, Neo4j), and caching strategies for large-scale systems.
  • Consistency: eventual consistency vs. strong consistency for unfriending in a distributed environment.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.