Merge In Between Linked Lists
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given the heads of two singly linked lists, list1 and list2, along with two integers a and b that are 0-indexed positions in list1.
Delete every node of list1 whose position is between a and b inclusive, and splice the entire list2 into the gap: the node at position a - 1 must point to the head of list2, and the last node of list2 must point to the node that was at position b + 1.
Return the head of the resulting list. It is guaranteed that a >= 1 and b <= list1.length - 2, so the head and tail of list1 always survive. Aim for O(n + m) time and O(1) extra space.
Examples
Constraints
- 3 <= list1.length <= 10^4
- 1 <= a <= b < list1.length - 1
- 1 <= list2.length <= 10^4
- -10^6 <= Node.val <= 10^6
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.