|
U
Pro64. Merge Two Sorted Linked Lists
Easy
Problem Description
Merge two sorted singly linked lists into a single sorted linked list.
Input Format
- •Line 1: Two space-separated integers N and M.
- •Line 2: N sorted integers.
- •Line 3: M sorted integers.
Output Format
Print N+M sorted integers space-separated.
Example 1:
Input:
3 3 1 2 4 1 3 4
Output:
1 1 2 3 4 4
Explanation: Merged sorted sequence.
Example 2:
Input:
2 0 5 10
Output:
5 10
Explanation: Second list empty.
Example 3:
Input:
1 2 2 1 3
Output:
1 2 3
Explanation: Lists merged into 1 2 3.
Constraints:
Standard integer bounds: 32-bit signed integer or input range [1, 10^5].Time complexity target: O(N) or O(N log N) where applicable.Auxiliary space target: O(1) or minimal auxiliary memory.
Follow up:Can this algorithm be adapted to an online streaming setting where the entire input cannot be held in memory simultaneously?
1,180 Online
Code
|Loading Code Editor...
SavedLn 1, Col 1
param_1 =
param_2 =
param_3 =
Sandboxed Engine
Ctrl+Enter = Run | Ctrl+Shift+Enter = Submit