Practice/Amazon/Design a Product Stock Availability Service
Object Oriented DesignMust
You are building an inventory management system for a large e-commerce platform that operates multiple distribution centers across different regions. Each warehouse maintains its own independent database tracking product inventory levels. When a customer attempts to purchase a product, the system needs to quickly determine whether sufficient stock exists across all warehouses to fulfill the order.
Design and implement a function that checks whether a specific product has enough total inventory across all warehouses to satisfy a customer's order quantity. The function should aggregate stock levels from multiple warehouse databases and return whether the order can be fulfilled.
Example 1:
Input: product_id = "LAPTOP-X1" quantity_needed = 3 warehouses = [ \{"id": "NYC", "stock": \{"LAPTOP-X1": 2, "PHONE-A": 10\}\}, \{"id": "LA", "stock": \{"LAPTOP-X1": 5, "TABLET-B": 7\}\} ] Output: true Explanation: NYC has 2 units and LA has 5 units of LAPTOP-X1, totaling 7 units which exceeds the required 3 units.
Example 2:
Input: product_id = "MONITOR-Z" quantity_needed = 10 warehouses = [ \{"id": "CHICAGO", "stock": \{"MONITOR-Z": 3\}\}, \{"id": "DALLAS", "stock": \{"MONITOR-Z": 4\}\}, \{"id": "MIAMI", "stock": \{"KEYBOARD-K": 20\}\} ] Output: false Explanation: Only 7 units are available (3 + 4 + 0), which is less than the required 10 units.
Example 3:
Input: product_id = "HEADSET-H" quantity_needed = 1 warehouses = [ \{"id": "SEATTLE", "stock": \{"MOUSE-M": 15\}\}, \{"id": "BOSTON", "stock": \{"CABLE-C": 30\}\} ] Output: false Explanation: The product HEADSET-H is not available in any warehouse.