FastPrepWarehouse and Regional Inventory Operations

Warehouse and Regional Inventory Operations

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN

Problem statement

Maintain quantities of item types at several warehouses. Each warehouse belongs to one fixed region, and every warehouse starts empty. The aligned arrays warehouseIds and regions define this assignment.

For this exercise, process the finite sequence operations in order. Item types are identified by strings. Each operation is one string-array row:

  • ["ADD", warehouse, item, quantity]: increase this warehouse's quantity of the item by the positive integer quantity. Return the new warehouse quantity as decimal text.
  • ["DELETE", warehouse, item]: remove all stock of that item at this warehouse. Return the removed quantity as decimal text, or "0" when none was stored.
  • ["WAREHOUSE_QTY", warehouse, item]: return this warehouse's current quantity of the item as decimal text.
  • ["REGION_QTY", region, item]: return the sum of this item's current quantity across all warehouses in the region as decimal text.
  • ["MIN_ITEM", region, item1, item2, ...]: among the listed candidate item types, return the item with the smallest regional quantity. Break ties by lexicographically smaller item ID. Repeated candidates do not change the result. With no candidates, return "".

An absent item has quantity 0. A region with no warehouses also has quantity 0 for every item. Every operation that names a warehouse uses a valid warehouse ID; region queries may name an empty region. Warehouse assignments never change. A deletion affects only the named warehouse, not other warehouses that store the same item.

The problem statement continues
Pro

Examples

Example 1

warehouseIds = ["w1","w2","w3"]regions = ["east","east","west"]operations = [["ADD","w1","apple","5"],["ADD","w2","apple","2"],["ADD","w3","apple","9"],["REGION_QTY","east","apple"],["WAREHOUSE_QTY","w1","apple"],["MIN_ITEM","east","apple","pear"]]return = ["5","2","9","7","5","pear"]

The east region holds 5 + 2 = 7 apples; the west warehouse is excluded. Pears have quantity 0, so pear is the least-stocked candidate in east.

FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Amazon hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week