You’re building a promotion engine for a high-traffic e-commerce marketplace (millions of DAUs). During flash sales, the system must quickly verify whether a fulfillment center can assemble a promo bundle from its current inventory. A wrong “yes” can cause overselling and cancellations; a wrong “no” can suppress revenue.
Implement a function:
haystack: a list of items currently in inventory (may contain duplicates)needle: a list of items required to assemble one promo bundle (may contain duplicates)True if haystack contains every item in needle with at least the same multiplicity.False.Items are represented as strings (e.g., SKU codes). Order does not matter.
Formally, for every distinct item x, let count(A, x) be the number of occurrences of x in list A. You must return True iff:
x: count(haystack, x) >= count(needle, x)haystack = ["sku1", "sku2", "sku1", "sku3"], needle = ["sku1", "sku1"]Truehaystack has two copies of "sku1", which satisfies the bundle requirement.haystack = ["mask", "gloves"], needle = ["mask", "mask"]False"mask" items, but inventory has only one.0 <= haystack.length, needle.length <= 2 * 10^51..30needle is empty, return True.haystack is empty and needle is non-empty, return False.