Replace Linked List on Index
You are given two linked lists a
and b
as well as integers lo
and hi
.
Remove a
’s nodes from indices (0-indexed) [lo, hi]
inclusive and insert b
in this place.
Constraints
0 ≤ n ≤ 100,000
wheren
is the number of nodes ina
0 ≤ m ≤ 100,000
wherem
is the number of nodes inb
https://binarysearch.com/problems/Replace-Linked-List-on-Index
Examples
Example 1
Input
- a =
- b =
- lo =
1
- hi =
2
Output
- answer =
Explanation
We removed nodes 2
and 3
since their indices are in [1, 2]
. In its place we inserted b
.
Example 2
Input
- a =
- b =
- lo =
0
- hi =
2
Output
- answer =
Explanation
We removed every node of a
and inserted b
.
Leave a comment