Match the Warehouse Label Contents
Context
A warehouse receives two shipment labels for parcels that may have been printed in different character orders. The labels are made only of lowercase letters. The dispatch team needs to know whether both labels contain exactly the same letters, including repeated letters, even if their order differs.
Problem
Write a function that checks whether two shipment labels contain the same multiset of lowercase letters. The order of letters does not matter, but every repeated letter must appear the same number of times in both labels. Return true when the labels have equal lengths and matching letter counts; otherwise return false. An empty label is valid and matches another empty label. Do not modify the input strings.
Examples
label_a = "staple"label_b = "plates"Truelabel_a = "letter"label_b = "teller"Falselabel_a = ""label_b = ""TrueConstraints
0 <= len(label_a) <= 100label_a: alphabet lowercase0 <= len(label_b) <= 100label_b: alphabet lowercaselabel_a and label_b contain only lowercase letters.- Types:
label_ais str,label_bis str; result is bool
Function signature
def labels_have_same_contents(label_a: str, label_b: str) -> bool
label_astr- The first lowercase shipment label.
label_bstr- The second lowercase shipment label.
- returns bool
- Return true exactly when both labels contain identical letters with identical multiplicities, regardless of order.
Adapted from MBPP problem task_532 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- Whitespace and punctuation do not occur because labels contain only lowercase letters.
- Empty labels are permitted.