Skip to main content
hard

Carnival Concession Inventory

Also known as: Perishable Inventory with FEFO

Carnival Concession Inventory - OpenAI Interview Style

You're managing perishable inventory where items expire—and the oldest expiring stock must sell first. The twist is events arrive out of order, so you need to reconstruct the timeline before allocating. A great intro to priority-based resource management with a fun carnival framing.

Examples

You write

CarnivalInventory: add_batch(timestamp: int, batch_id: str, item_id: str, quantity: int, expiration_timestamp: int), sell(timestamp: int, item_id: str, quantity: int), get_stock(timestamp: int, item_id: str)

  1. Example 1

    Input
    addBatch(1,"b1","hotdog",10,100), getStock(1,"hotdog")→10, sell(5,"hotdog",3), getStock(5,"hotdog")→7
    returns
    [10, 7]
  2. Example 2

    Input
    Multiple items
    returns
    [5, 10]

The pattern behind it

Design

I reach for it when

  • The statement describes a class with methods, not one function.
  • Each method needs to be fast, and the structure decides how fast.

Say this before you type. Say each method, the cost you want from it, and the structure that earns that cost.

All 27 Design problems

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.

1Basic Inventorymedium
2Part 2
3Part 3
4Part 4

Each locked part opens in the editor once the part before it passes.