Replace a Range of Playlist Nodes With Another Playlist

Last updated: November 29, 2026

Quick Overview

Given playlist A as a singly linked list, two zero-based positions a and b with 1 <= a <= b < len(A) - 1, and playlist B, remove nodes a through b of A and splice all of B in their place.

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

0

0

0 solved


Given playlist A as a singly linked list, two zero-based positions a and b with 1 <= a <= b < len(A) - 1, and playlist B, remove nodes a through b of A and splice all of B in their place.

A Google phone screen splicing exercise in a YouTube playlist framing. The interviewer looks for precise index walking to the node before a and the node after b, and for an O(1) connection to B's tail.

What the Interviewer Expects
  • Locate the node at a - 1 and the node at b + 1 in one walk
  • Find B's tail before splicing
  • Connect a-1 to B's head and B's tail to b+1
  • State the index assumptions and what happens if B is empty
  • O(len(A) + len(B)) time, O(1) space
Key Topics to Cover
linked list
splicing
index walking
pointer surgery
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
  • Allow a = 0, so the head of A may be replaced.
  • Do it when B might be empty.
  • Support many range replacements given in any order.
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: head of A, integers a and b, head of B (non-empty).
  • Constraints: 1 <= a <= b < len(A) - 1, so both a node before and a node after the range exist.
  • Output: head of A after the splice. Reu...
High-Level Design

Walk A once with an index. When the index reaches a - 1, remember that node as before. Continue to index b + 1 and remember that node as after. Separately walk B to its tail. Then do two pointer w...


Submit Your Answer
Markdown supported