You get inventory, a dict from item names to how many of each item a shop has. You also get the item a customer just bought.
Sell one item and return the updated dictionary.
The count of item drops by 1. When it reaches 0, remove item from the dictionary. The order of the entries doesn't matter.
Example 1:
Input: inventory = {"apples": 5, "pears": 2}, item = "apples"
Output: {"apples": 4, "pears": 2}
Explanation: One apple is sold, so 5 - 1 = 4 apples are left.
Example 2:
Input: inventory = {"cups": 1, "plates": 3}, item = "cups"
Output: {"plates": 3}
Explanation: The last cup is sold. No cups are left, so "cups" is removed.
Example 3:
Input: inventory = {"pen": 1}, item = "pen"
Output: {}
Explanation: The only pen is sold. Nothing is left in the shop.
Constraints:
itemis always a key ofinventory.- Every count is at least 1.
- Item names are single lowercase words.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
