Find Where Two Reply Chains Merge Into a Shared Tail

Last updated: November 29, 2026

Quick Overview

Two singly linked reply chains may merge at some node and share every node after it. Return the first shared node, or None if they never merge, in O(m + n) time and O(1) space.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Two singly linked reply chains may merge at some node and share every node after it. Return the first shared node, or None if they never merge, in O(m + n) time and O(1) space.

A Meta phone-screen Easy framed around comment threads that converge on a common reply chain. The interviewer wants to see the two-pointer trick where each pointer switches to the other list's head, and an explanation of why they meet at the intersection or both reach None together.

What the Interviewer Expects
  • Clarify intersection means the same node object, not equal values
  • Give the hash set baseline
  • Present the length-difference or pointer-switching approach
  • Explain why the switching pointers meet
  • Handle the no-intersection case without looping forever
Key Topics to Cover
Linked list
Two pointers
Intersection
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if either list might contain a cycle?
  • Find the intersection of k lists.
  • How would you detect a shared tail across machines where you only have node IDs?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: heads a and b. Output: the first node reachable from both, compared by identity. The lists must keep their structure and there are no cycles. Lengths m and n can differ....

High-Level Design

Walk pointer p through a then b, and pointer q through b then a. Both travel exactly m + n steps in total before both are None. If the lists share a tail of length c, then after p walks a's private pa...


Submit Your Answer
Markdown supported