← Google Interview Insights

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

IntermediatePrefer not to say
Apr 2026

Summary

Google SWE coding round, one problem the whole session. Linked list ancestry traversal, which sounds straightforward until you're actually in it and second-guessing your pointer logic.

Questions Asked (1)

Q1

Given two singly-linked chains representing ancestor paths (each node has an id and a parent pointer), determine whether the two chains share any common node.

Algorithms & Data Structures
Author's notes

The core insight is just traversal and a hash set, collect all nodes from one chain then walk the other and check for membership.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose an efficient algorithm such as two-pointer intersection or hashing. Discuss time and space complexity trade-offs and handle edge cases like no intersection or different lengths.

Pro tip: Mention that if the lists are very long, the two-pointer approach is optimal with O(1) space, but if memory is not a concern, a hash set is simpler. Also, consider if the lists are mutable or if there's a cycle.

1. Clarify the problem

Ask if the lists are singly-linked with parent pointers (so each node points to its parent, forming a path to the root). Confirm whether we need to find any common node or the first common node, and if the lists can have cycles.

2. Consider brute force and hashing

A simple approach is to traverse one list and store nodes in a hash set, then traverse the other list and check for existence. This takes O(m+n) time and O(m) or O(n) space.

3. Optimize to O(1) space

Use the two-pointer technique: find the lengths of both lists, advance the pointer of the longer list by the difference, then move both pointers in tandem until they meet or reach the end. This finds the intersection in O(m+n) time and O(1) space.

4. Handle edge cases

Discuss cases where one or both lists are empty, no intersection exists, or the intersection is at the root. Also, if cycles are possible, detect and handle them (e.g., using Floyd's cycle detection).

5. Analyze complexity and trade-offs

Compare the hashing and two-pointer approaches in terms of time and space. Mention that the two-pointer method is more space-efficient but requires two passes to compute lengths, while hashing is simpler but uses extra space.

Key Points to Mention

  • Time complexity: O(m+n) for both approaches
  • Space complexity: O(1) for two-pointer, O(m) or O(n) for hashing
  • Two-pointer technique: align lengths then move together
  • Hash set approach: store nodes of one list and check the other
  • Edge cases: empty lists, no intersection, intersection at root
  • Cycle handling: use Floyd's algorithm if cycles are possible

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