← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

Intermediate
May 2026

Summary

Interviewed at Google for a SWE role. The content shared was just a title, 'Degrees of Friendship', which sounds like a graph problem, probably BFS or shortest path between nodes in a social network. Not much else to go on.

Questions Asked (1)

Q1

Given a social network represented as a graph, find the degree of connection (shortest path) between two people.

Algorithms & Data Structures
Author's notes

Classic BFS setup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the social network as an unweighted graph and use BFS to find the shortest path between the two people, as BFS guarantees the minimum number of edges. Discuss the algorithm's time and space complexity, and consider optimizations like bidirectional BFS for large graphs.

Pro tip: Mention that bidirectional BFS can significantly reduce the search space by exploring from both ends simultaneously, often cutting time complexity from O(b^d) to O(b^(d/2)). Also, clarify assumptions about graph size, memory constraints, and whether the graph is static or dynamic.

1. Clarify the problem and constraints

Ask about graph size, whether it's directed or undirected, if edge weights are uniform, and if there are any memory or latency constraints. Confirm that 'degree of connection' means the shortest path length in terms of number of edges.

2. Choose the right algorithm

Select BFS for unweighted graphs to find the shortest path. If the graph is very large, consider bidirectional BFS to reduce search space. Avoid DFS as it doesn't guarantee shortest paths.

3. Outline the BFS approach

Describe initializing a queue with the source node, a visited set, and a distance counter. Process nodes level by level, tracking distance, and stop when the target is found or the queue is exhausted.

4. Analyze complexity and edge cases

State time complexity O(V+E) and space O(V) for standard BFS. Discuss edge cases: disconnected nodes, source equals target, and very large graphs requiring distributed or approximate methods.

5. Propose optimizations and extensions

Mention bidirectional BFS for performance, using adjacency lists for sparse graphs, and handling dynamic graphs with incremental updates. Optionally, discuss weighted graphs (Dijkstra) if edges have weights.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graphs
  • Time and space complexity: O(V+E) time, O(V) space
  • Bidirectional BFS optimization for large graphs
  • Handling disconnected graphs and unreachable nodes
  • Graph representation: adjacency list vs. adjacency matrix
  • Potential need for distributed processing if graph is massive

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