#C12339. Merge Two Sorted Lists
Merge Two Sorted Lists
Merge Two Sorted Lists
You are given two lists of integers, each of which is sorted in ascending order. Your task is to merge these two lists into a single sorted list.
The merging process should be performed in linear time using the two-pointer technique. More formally, if the first list has length \(n\) and the second has length \(m\), you can merge them in \(O(n+m)\) time.
Please note: Input will be read from stdin and output should be written to stdout.
inputFormat
The input consists of four lines:
- The first line contains an integer \(n\), representing the number of elements in the first list.
- The second line contains \(n\) space-separated integers, representing the first sorted list.
- The third line contains an integer \(m\), representing the number of elements in the second list.
- The fourth line contains \(m\) space-separated integers, representing the second sorted list.
outputFormat
Output a single line containing the merged sorted list. The numbers should be separated by a single space.
## sample3
1 3 5
3
2 4 6
1 2 3 4 5 6