Splice Two Sorted Gmail Label Feeds Into One Linked List

Last updated: November 29, 2026

Quick Overview

Two singly linked lists hold message timestamps for two Gmail labels, each sorted ascending. Merge them into one sorted list by relinking the existing nodes rather than allocating new ones.

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

0

0

0 solved


Two singly linked lists hold message timestamps for two Gmail labels, each sorted ascending. Merge them into one sorted list by relinking the existing nodes rather than allocating new ones.

Shows up early in Google phone screens as a building block for merge sort and k-way merge. The interviewer checks whether you use a dummy head to avoid special-casing the first node and whether you attach the leftover tail in O(1).

What the Interviewer Expects
  • Use a sentinel (dummy) node so the head needs no special case
  • Relink existing nodes, no new allocation
  • Keep the merge stable: on ties take from the first list
  • Attach the remaining tail directly instead of looping over it
  • State O(m + n) time and O(1) extra space
Key Topics to Cover
linked list
merge
sentinel node
two pointers
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
  • Merge k label feeds instead of two.
  • Write the recursive version and discuss its stack depth.
  • The feeds are sorted descending. What changes?
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
  • Inputs: heads a and b, each sorted ascending, either may be empty.
  • Output: head of a single ascending list containing every node from both.
  • Reuse nodes; extra space O(1)....
High-Level Design

Keep a tail pointer starting at a dummy node. Repeatedly compare the fronts of the two lists, move the smaller node onto the tail, and advance that list. When one list runs out, the other is already s...


Submit Your Answer
Markdown supported