← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Google coding round for a software engineer role. One question, a tree problem dressed up with a fun theme, and I spent more time second-guessing my data structure choice than actually solving it.

Questions Asked (1)

Q1

Given a horse family tree (genealogy data) and two horses, determine whether the two horses share a blood relation.

Algorithms & Data Structures
Author's notes

It's basically lowest common ancestor but reframed as a genealogy problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the horse family tree as a graph where nodes are horses and edges represent parent-child relationships, then determine if there is a path between the two horses. Use BFS/DFS from one horse to find the other, or compute the lowest common ancestor (LCA) if the tree is rooted. Clarify whether 'blood relation' means any shared ancestor or a direct lineage, and handle potential cycles or multiple parents.

Pro tip: Always clarify the definition of 'blood relation' with the interviewer—whether it includes indirect relations (e.g., cousins) or only direct ancestors/descendants—as this significantly impacts the algorithm and shows attention to detail.

1. Clarify Requirements

Ask the interviewer to define 'blood relation' (e.g., any shared ancestor vs. direct lineage) and confirm the data structure (tree, graph, multiple parents).

2. Choose Data Structure

Represent the genealogy as a graph (adjacency list) or tree (parent pointers). If it's a tree, identify the root; if not, treat as an undirected graph.

3. Select Algorithm

For general graphs, use BFS/DFS to check connectivity. For trees, compute LCA or traverse ancestors. Consider time/space complexity.

4. Handle Edge Cases

Account for cycles, multiple parents, disconnected components, and the horses being the same. Discuss how to handle large datasets.

5. Optimize and Discuss Trade-offs

If needed, preprocess the tree for LCA (e.g., binary lifting) to answer queries in O(log n). Compare with BFS/DFS for single query.

Key Points to Mention

  • Graph representation: adjacency list vs. parent pointers
  • BFS/DFS for connectivity or path finding
  • Lowest Common Ancestor (LCA) for rooted trees
  • Time and space complexity analysis (e.g., O(V+E) for BFS)
  • Handling cycles and multiple parents (if applicable)
  • Preprocessing for multiple queries (e.g., binary lifting)

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