Flash Sale Order Processor

Hard ⏱ 18 min 25% acceptance ★★★★☆ 4.3
A flash sale has limited stock per SKU. Write process(stock, orders) where stock is a dict sku → qty and orders are (order_id, sku, qty) in arrival order: fulfill fully when stock allows (decrement), else reject entirely (no partial fills). Return (fulfilled_ids, rejected_ids).

Examples

Example 1
Input
process({'tv': 3}, [(1, 'tv', 2), (2, 'tv', 2), (3, 'tv', 1)])
Output
([1, 3], [2])
Explanation

Order 2 wanted 2 with only 1 left — rejected whole; order 3 took the last unit.

Constraints

  • No partial fulfillment.
  • Process strictly in order.

Topics

Business Logicordered allocation

Companies

FlipkartAmazonMeesho

Hints

Hint 1

Check stock.get(sku, 0) >= qty.

Hint 2

Two accumulator lists.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.