Merge In Between Linked Lists

Medium · Linked Lists · about 15 minutes

Asked at Amazon, Google, Microsoft.

Given linked lists list1 and list2 and indices a ≤ b (0-indexed, 1 ≤ a, b < len(list1) - 1), remove nodes a..b of list1 and put list2 in their place. Return the head of the result.