Combine Sorted Warehouse Dispatch Lists
Context
A logistics hub receives two dispatch lists from separate warehouses. Each list is already ordered by package priority number, from smallest to largest. The hub needs one combined dispatch list that keeps the same ordering and includes every package entry, even when several packages share a priority number.
Problem
Implement a function that combines two nondecreasing integer arrays into one nondecreasing array. Every element from both input arrays must appear in the returned array exactly as many times as it appears in its source array. If one array has no remaining elements, continue taking elements from the other array. Equal values must not be discarded. Use the ordering already present in the inputs rather than treating the data as unsorted.
Examples
warehouse_a = [1, 4, 7]warehouse_b = [2, 4, 6][1, 2, 4, 4, 6, 7]warehouse_a = [-5, -2, 0, 0, 3]warehouse_b = [-4, -2, 1][-5, -4, -2, -2, 0, 0, 1, 3]warehouse_a = [2, 2, 8]warehouse_b = [][2, 2, 8]Constraints
0 <= len(warehouse_a) <= 100000-1000000000 <= warehouse_a[i] <= 1000000000 for every iwarehouse_a: sorted non decreasing0 <= len(warehouse_b) <= 100000-1000000000 <= warehouse_b[i] <= 1000000000 for every iwarehouse_b: sorted non decreasing- Types:
warehouse_ais int[],warehouse_bis int[]; result is int[]
Function signature
def merge_dispatch_lists(warehouse_a: list[int], warehouse_b: list[int]) -> list[int]
warehouse_alist[int]- The first warehouse's dispatch priorities in nondecreasing order.
warehouse_blist[int]- The second warehouse's dispatch priorities in nondecreasing order.
- returns list[int]
- A new array containing the multiset union of both inputs in nondecreasing order, including all duplicate occurrences.
Adapted from MBPP problem task_943 (CC BY 4.0). Rewritten, extended and verified by Iksha.