Cisco Online Assessment Question
Anonymous User
2792

Compute the best way an order can be shipped (called shipments) given inventory across a set of warehouses (called inventory distribution).

Implement InventoryAllocator class to produce the cheapest shipment.

The first input will be an order: a map of items that are being ordered and how many of them are ordered. For example an order of apples, bananas and oranges of 5 units each will be

{ apple: 5, banana: 5, orange: 5 }

The second input will be a list of object with warehouse name and inventory amounts (inventory distribution) for these items. For example the inventory across two warehouses called owd and dm for apples, bananas and oranges could look like

[ { name: owd, inventory: { apple: 5, orange: 10 } }, { name: dm:, inventory: { banana: 5, orange: 10 } } ]

You can assume that the list of warehouses is pre-sorted based on cost. The first warehouse will be less expensive to ship from than the second warehouse.

Examples

Happy Case, exact inventory match!*

Input: { apple: 1 }, [{ name: owd, inventory: { apple: 1 } }]
Output: [{ owd: { apple: 1 } }]

Not enough inventory -> no allocations!

Input: { apple: 1 }, [{ name: owd, inventory: { apple: 0 } }]
Output:[]

Should split an item across warehouses if that is the only way to completely ship an item:

Input: { apple: 10 }, [{ name: owd, inventory: { apple: 5 } }, { name: dm, inventory: { apple: 5 }}]
Output: [{ dm: { apple: 5 }}, { owd: { apple: 5 } }]

Comments (5)