Merging Sorted Linked Lists
Two sorted linked lists can be merged in linear time using two pointers. At each step, compare the current nodes and attach the smaller node to the result. A dummy node simplifies head handling and eliminates special cases.
Time complexity: O(m + n).
Auxiliary space: O(1) when existing nodes are reused.
The dummy node simplifies result-list construction.
The original lists can be reused if mutation is acceptable.
A new-node implementation would require additional memory.
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience