Merge In Between Linked Lists
Problem Statement
You get two linked lists, list1 and list2. Positions in list1 start at 0.
Remove the nodes of list1 from position a to position b, both ends included. Then put all of list2 in their place. Afterwards, list2 sits between the node at position a − 1 and the node that was at position b + 1. Return the head of list1.
list1 and list2, plus two positions a and b (with a ≤ b) that refer to list1.
The head of list1 after the nodes from a to b are replaced by list2.
Positions 3 and 4 (values 3 and 4) are removed. list2 goes in their place, and the 5 stays at the end.
Positions 2 to 5 (values 2, 3, 4, 5) are removed. The 0 and the 1 stay before list2, and the 6 stays after it.
- • list1 has between 3 and 10^4 nodes.
- • list2 has between 1 and 10^4 nodes.
- • 1 ≤ a ≤ b < n − 1, where n is the number of nodes in list1. So there is always a node before the gap and a node after it.
- • The node values are between 0 and 10^6.
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Put the nodes of both lists in vectors, build the new order, relink
Walk to node a − 1 and node b, splice list2 in, link its tail to node b + 1
Changing links in the middle of a list is easy to get wrong. A vector makes the new order obvious. Put the nodes of list1 and of list2 into two vectors. The new order is the first a nodes of list1, then all of list2, then the nodes after position b. Link each node to the next one in that order.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Linked List — Reversal translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.