Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Model an inventory item with validation

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.

Requirements

  • qty < 0 is invalid at construction.
  • receive(n) rejects n <= 0.
  • safe_make returns a dict or None instead of raising.

Constraints

  • Function safe_make(sku, qty).
  • Callers of the class still see exceptions.
  • safe_make is the soft path.

Examples

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

intermediate

Model an inventory item with validation

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.