PracticeArrays

Match Two Warehouse Manifests

EasyArraystraversalcomparisonstate tracking Time not estimated Not started

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

Example 1
Input: first_manifest = [["pallet", "fragile"], ["crate", "sealed"]]second_manifest = [["pallet", "fragile"], ["crate", "sealed"]]
Output: True
Explanation: The two manifests have matching records and labels in corresponding positions, so the executed result is true. (fact_ids: )
Example 2
Input: first_manifest = [["box", "blue"], ["box", "blue"], ["crate", "small"]]second_manifest = [["box", "blue"], ["crate", "small"], ["box", "blue"]]
Output: False
Explanation: The second and third records occur in different positions between the manifests, so the executed result is false. (fact_ids: )
Example 3
Input: first_manifest = [["label", "priority"], ["item", "count", "ready"]]second_manifest = [["label", "priority"], ["item", "count"]]
Output: False
Explanation: The second corresponding records have different numbers of labels, so the executed result is false. (fact_ids: )

Constraints

  • 0 <= len(first_manifest) <= 80
  • 1 <= len(first_manifest[i]) <= 5 for every i
  • 1 <= len(first_manifest[i][j]) <= 16 for every i, j
  • first_manifest[i][j]: alphabet lowercase
  • 0 <= len(second_manifest) <= 80
  • 1 <= len(second_manifest[i]) <= 5 for every i
  • 1 <= len(second_manifest[i][j]) <= 16 for every i, j
  • second_manifest[i][j]: alphabet lowercase
  • first_manifest and second_manifest contain words with only lowercase letters.
  • Types: first_manifest is str[][], second_manifest is str[][]; result is bool

Function signature

def manifests_match(first_manifest: list[list[str]], second_manifest: list[list[str]]) -> bool
first_manifest list[list[str]]
The first ordered warehouse manifest, represented as shipment records containing lowercase labels.
second_manifest list[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.
Approved · c036-abs_211_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1