Merge Two Sorted Linked Lists
Easyjavapythonccppjavascript
Given two sorted singly linked lists, merge them into one sorted linked list and print it.
Input Format
The first line contains an integer N. The second line contains N space-separated integers in non-decreasing order (list A; empty if N is 0). The third line contains an integer M. The fourth line contains M space-separated integers in non-decreasing order (list B; empty if M is 0).
Output Format
Print the merged sorted list, separated by single spaces. Print an empty line if both lists are empty.
Example 1
Input
3 1 3 5 3 2 4 6
Output
1 2 3 4 5 6
Explanation: Nodes from both lists are taken in increasing order.
- 0 <= N, M <= 100000
- -1000000000 <= value <= 1000000000