Write a restriction rule engine for a shopping basket (bulk-buy limits per product and per category), returning MET/BREACHED.
Asked in the Coding round stage. Candidate linked LeetCode 3227767 Round 1 as the question asked.
Implement a function that checks whether a basket satisfies all bulk-buy limits.
def check_basket_restrictions(basket, product_limits, category_limits):
basket is a list of items, where each item is a dict with keys product, category, and quantity.product_limits maps product name to the maximum allowed total quantity.category_limits maps category name to the maximum allowed total quantity."MET" if every limit is respected, otherwise return "BREACHED".Example 1
basket = [{"product": "milk", "category": "dairy", "quantity": 2}, {"product": "bread", "category": "bakery", "quantity": 1}]
product_limits = {"milk": 2, "bread": 2}
category_limits = {"dairy": 3, "bakery": 2}
Output: "MET"
Example 2
basket = [{"product": "eggs", "category": "dairy", "quantity": 4}, {"product": "yogurt", "category": "dairy", "quantity": 1}]
product_limits = {"eggs": 4, "yogurt": 2}
category_limits = {"dairy": 4}
Output: "BREACHED"
1 <= len(basket) <= 10^41 <= quantity <= 10^9basket appears in the corresponding limits mapdef check_basket_restrictions(basket, product_limits, category_limits):