Match Two Warehouse Manifests
Context
A fulfillment company records the shipment labels scanned at two warehouses. Each manifest is an ordered list of shipment records, and each record contains a fixed sequence of lowercase labels. Determine whether the two manifests describe exactly the same records in the same order, including repeated records and repeated labels.
Problem
Write a function that checks whether two warehouse manifests are structurally identical. A manifest is an ordered list of shipment records. Each record is represented by a list of lowercase words, and its position within the record matters. The manifests match only if they contain the same number of records, corresponding records have the same number of labels, and every corresponding label is identical. Preserve duplicates and order: records or labels appearing more than once must be compared at their exact positions. Return false as soon as a length or content mismatch is found; return true only after every corresponding part agrees.
Examples
first_manifest = [["pallet", "fragile"], ["crate", "sealed"]]second_manifest = [["pallet", "fragile"], ["crate", "sealed"]]Truefirst_manifest = [["box", "blue"], ["box", "blue"], ["crate", "small"]]second_manifest = [["box", "blue"], ["crate", "small"], ["box", "blue"]]Falsefirst_manifest = [["label", "priority"], ["item", "count", "ready"]]second_manifest = [["label", "priority"], ["item", "count"]]FalseConstraints
0 <= len(first_manifest) <= 801 <= len(first_manifest[i]) <= 5 for every i1 <= len(first_manifest[i][j]) <= 16 for every i, jfirst_manifest[i][j]: alphabet lowercase0 <= len(second_manifest) <= 801 <= len(second_manifest[i]) <= 5 for every i1 <= len(second_manifest[i][j]) <= 16 for every i, jsecond_manifest[i][j]: alphabet lowercasefirst_manifest and second_manifest contain words with only lowercase letters.- Types:
first_manifestis str[][],second_manifestis str[][]; result is bool
Function signature
def manifests_match(first_manifest: list[list[str]], second_manifest: list[list[str]]) -> bool
first_manifestlist[list[str]]- The first ordered warehouse manifest, represented as shipment records containing lowercase labels.
second_manifestlist[list[str]]- The second ordered warehouse manifest to compare with the first.
- returns bool
- True when both manifests have identical lengths, record shapes, and labels at every corresponding position; otherwise false.
Adapted from MBPP problem task_811 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- An empty manifest is valid.
- Inner lists are the tuple-like shipment records; their lengths may differ between the two inputs.