PracticeArrays

Tri-Manifest Matching Shipments

EasyArraystraversalaccumulationcomparison Time not estimated Not started

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

Example 1
Input: manifest_a = [101, 202, 303, 404]manifest_b = [101, 999, 303, 888]manifest_c = [101, 202, 303, 777]
Output: [101, 303]
Explanation: The executed result is [101, 303]. These are the matching codes retained in the result for example 1.
Example 2
Input: manifest_a = [7, 7, 12, 20]manifest_b = [7, 9, 12, 20]manifest_c = [7, 7, 12, 5]
Output: [7, 12]
Explanation: The executed result is [7, 12]. The result preserves the matching codes from example 2, while separate positions are not required to produce duplicate output here.
Example 3
Input: manifest_a = [15, 25, 35]manifest_b = [15, 26]manifest_c = [14, 25, 35, 45]
Output: []
Explanation: The executed result is [] because example 3 has no common position whose three codes are equal.

Constraints

  • 0 <= len(manifest_a) <= 100
  • -100000 <= manifest_a[i] <= 100000 for every i
  • 0 <= len(manifest_b) <= 100
  • -100000 <= manifest_b[i] <= 100000 for every i
  • 0 <= len(manifest_c) <= 100
  • -100000 <= manifest_c[i] <= 100000 for every i
  • Types: manifest_a is int[], manifest_b is int[], manifest_c is 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_a list[int]
Shipment codes from the first manifest, in processing order.
manifest_b list[int]
Shipment codes from the second manifest, in processing order.
manifest_c list[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.

Approved · cb045-abs_154_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1