Replace the nodes at indices a through b, inclusive, in list1 with all the nodes of list2. Indices start at 0. Connect the remaining prefix of list1 to list2, then connect the end of list2 to the remaining suffix of list1. Return the head of the combined list. Arrays in examples and test inputs show node values from head to tail.
Filled nodes in list1 are removed; list2 replaces them. The diagram below the arrow shows the resulting list.
Example 1:
Input: list1 = [2,4,6,8,10]
a = 1
b = 3
list2 = [7,9]
Output: [2,7,9,10]Explanation: Remove the nodes at indices 1, 2, and 3, which contain 4, 6, and 8. Inserting 7 -> 9 between the remaining nodes gives 2 -> 7 -> 9 -> 10.
Example 2:
Input: list1 = [1,2,3]
a = 1
b = 1
list2 = [5]
Output: [1,5,3]Explanation: Only the middle node, containing 2, is removed. Replace it with the single node containing 5 to get 1 -> 5 -> 3.
Example 3:
Input: list1 = [4,4,4,4]
a = 2
b = 2
list2 = [4,4]
Output: [4,4,4,4,4]Explanation: Remove one node and insert two nodes in its place. Although every value is 4, the resulting list has five nodes rather than four.
Constraints:
3 <= list1.length <= 100001 <= a <= b < list1.length - 11 <= list2.length <= 10000