← back to unit
Medium
# power tools medium
Inventory Day
The shop opens with stock, the day brings deliveries (+) and sales (−), and the boss asks about a few items at closing. 🏪
You get opening stock as item:amount pairs, then changes as item:amount pairs (amounts can be negative, items always already in stock), then queries (comma-separated). For each query print <item> <final amount>.
Example:
Input: stock = "apple:10,pear:5", changes = ["apple:-3", "pear:2", "apple:-1"], queries = ["apple", "pear"]
Output:
apple 6
pear 7
Apple goes 10 - 3 - 1 = 6, and pear goes 5 + 2 = 7.
💡 need a hint?
pt-inventory-day.py🔒 given lines are locked — write your code in between
loading...