Python data engineering interview problem. Difficulty: intermediate. Pattern: OOP. About 15 minutes. Part of the Pro drill bank.
Inventory items cannot exist with a negative quantity. Construction should reject bad data; a helper may return None for callers that prefer not to catch exceptions.
Model InventoryItem so invalid quantities cannot be constructed, and implement safe_make as a non-throwing wrapper.
Input: safe_make('A', 2) Output: {'sku': 'A', 'qty': 2} This input follows the stated rules and produces this output.
Topics: lakebench, python, OOP.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Define a class representing an inventory item that rejects a negative quantity on construction.
Model InventoryItem so invalid quantities cannot be constructed, and implement `safe_make` as a non-throwing wrapper.