Merge Two Sorted Linked Lists
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write mergeLists(a, b). Each is the head of a linked list made of nodes { value, next }, where next is the following node, or null at the end; an empty list is null. Both lists are sorted from smallest to largest, and values may repeat. Return the head of one sorted list made by relinking the nodes of both, without making new ones. For example, mergeLists(list([1, 2, 4]), list([1, 3, 4])) returns the list 1, 1, 2, 3, 4, 4, where list builds a linked list from an array.
Your code must pass
- Merges two sorted lists
- Handles empty lists
- Keeps repeated values
- Reuses the original nodes