Linked lists make splicing cheap: re-pointing a single next reference moves an entire tail from one list to another. Merging two sorted lists is the classic example, and it is also the heart of merge sort.
At a departure gate, passengers wait in two lines, l1 and l2, each already in order of seat row (singly linked lists whose values never decrease). The agent combines them into a single line that is still in row order, without anyone new joining: re-link the existing nodes and return the head of the combined line. Do not create new nodes for the values. One test calls reuses_nodes(a, b), which builds two linked lists from the Python lists a and b, merges them with your function and returns True when the merged list consists of exactly the original nodes (none new, none lost).
Examples
Input: l1 = 2 -> 5 -> 9, l2 = 3 -> 5 -> 6 -> 11
Output: 2 -> 3 -> 5 -> 5 -> 6 -> 9 -> 11
Input: l1 = (empty), l2 = 4
Output: 4
Constraints
0 <= number of nodes in each list <= 500- Both input lists are sorted in non-decreasing order
Goals
- Use a dummy head node to avoid special-casing the first element
- Splice nodes from two lists into one by re-linking next references
- Attach the leftover tail once one list runs out