#K95017. Merge Two Sorted Lists and Remove Duplicates
Merge Two Sorted Lists and Remove Duplicates
Merge Two Sorted Lists and Remove Duplicates
You are given two sorted lists. Your task is to merge these two lists into one sorted list that contains only unique elements. In other words, after merging the two lists, remove any duplicate values and output the resulting list in sorted order.
Input Format: Two lines of input. The first line contains the elements of the first sorted list separated by spaces, and the second line contains the elements of the second sorted list separated by spaces. Each list may be empty.
Output Format: A single line with the merged sorted list of unique integers separated by a single space. If the resulting list is empty, no output should be produced.
Note: All numbers are integers and the final output must be sorted in ascending order.
The implementation should follow this formula in LaTeX for the merging and deduplication process:
inputFormat
The input consists of two lines. The first line is a list of integers separated by spaces representing the first sorted list. The second line is a list of integers separated by spaces representing the second sorted list. A line may be empty, implying an empty list.
outputFormat
A single line containing the merged sorted list with unique elements, separated by spaces. If the result is empty, output nothing.## sample
1 3 5 7 9
2 3 5 8
1 2 3 5 7 8 9