Unit 2 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Go through each item in the restock dictionary, and add/update it's quantity in the current inventory.
1) Loop through each entry in the restock dictionary
a) If the item (key) is already in the inventory, add the new quantity
b) If this is a new item, add it to the inventory and set the new quantity
2) Return the inventory once all changes have been made
⚠️ Common Mistakes
def restock_inventory(current_inventory, restock_list):
# Loop over restock_list items to update current_inventory
for item, quantity in restock_list.items():
if item in current_inventory:
current_inventory[item] += quantity
else:
current_inventory[item] = quantity
return current_inventory