Tri-Manifest Matching Shipments
Context
A distribution center receives three manifests for shipments handled during the same processing run. Each list records one integer shipment code in processing order, but the manifests may have different lengths. Find the codes whose entries agree at the same position in all three manifests.
Problem
Write a function that compares three integer shipment-code lists position by position. Only positions present in all three lists are considered. Whenever the three codes at one position are equal, add that code to the result. Keep matching codes in their original order, and keep repeated matches from different positions. Stop when the shortest list ends. If no common position matches, return an empty list.
Examples
manifest_a = [101, 202, 303, 404]manifest_b = [101, 999, 303, 888]manifest_c = [101, 202, 303, 777][101, 303]manifest_a = [7, 7, 12, 20]manifest_b = [7, 9, 12, 20]manifest_c = [7, 7, 12, 5][7, 12]manifest_a = [15, 25, 35]manifest_b = [15, 26]manifest_c = [14, 25, 35, 45][]Constraints
0 <= len(manifest_a) <= 100-100000 <= manifest_a[i] <= 100000 for every i0 <= len(manifest_b) <= 100-100000 <= manifest_b[i] <= 100000 for every i0 <= len(manifest_c) <= 100-100000 <= manifest_c[i] <= 100000 for every i- Types:
manifest_ais int[],manifest_bis int[],manifest_cis int[]; result is int[]
Function signature
def find_matching_shipments(manifest_a: list[int], manifest_b: list[int], manifest_c: list[int]) -> list[int]
manifest_alist[int]- Shipment codes from the first manifest, in processing order.
manifest_blist[int]- Shipment codes from the second manifest, in processing order.
manifest_clist[int]- Shipment codes from the third manifest, in processing order.
- returns list[int]
- The shipment codes whose values are equal at the same position in all three manifests, listed in encounter order with duplicates preserved.
Adapted from MBPP problem task_754 (CC BY 4.0). Rewritten, extended and verified by Iksha.