Merge two sorted code lists without repeats
Your task
Two warehouse zones each keep a sorted list of the product codes they stock. A code can repeat within one zone's list and can appear in both zones.
Write combined_catalogue(a, b) that returns the combined catalogue: every code that either zone stocks, once each, in increasing order.
Input and output:
a,b: the two zones' lists, each a list of 0 to 100,000 integers from -1,000,000,000 to 1,000,000,000, in non-decreasing order.- Returns a list of integers in strictly increasing order.
Rules:
- A code is in the result if it appears in
a, inb, or in both. - Each code appears in the result exactly once, however many times it appears in the inputs.
- Codes are ordered by numeric value.
- Two empty lists return an empty list.
Examples
combined_catalogue(a: list[int], b: list[int]) -> list[int]Example 1
Input
combined_catalogue([1, 3, 3, 5], [2, 3, 6])Output
[1, 2, 3, 5, 6]Example 2
Input
combined_catalogue([-5, 10, 10], [2, 100])Output
[-5, 2, 10, 100]