Bird
Raised Fist0
HLDsystem_design~10 mins

Inventory management in HLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the main component responsible for tracking stock levels.

HLD
class InventoryManager:
    def __init__(self):
        self.stock = [1]
Drag options to blanks, or click blank then click option'
A[]
Bset()
CNone
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a dictionary for stock storage.
Initializing stock as None which causes errors when updating.
2fill in blank
medium

Complete the code to add a new item with quantity to the inventory.

HLD
def add_item(self, item_id, quantity):
    if item_id in self.stock:
        self.stock[item_id] [1] quantity
    else:
        self.stock[item_id] = quantity
Drag options to blanks, or click blank then click option'
A+=
B-=
C*=
D/=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-=' which would decrease stock incorrectly.
Using '*=' or '/=' which are not appropriate for addition.
3fill in blank
hard

Fix the error in the code to correctly check if an item is available in stock.

HLD
def is_available(self, item_id):
    return self.stock.get(item_id, 0) [1] 0
Drag options to blanks, or click blank then click option'
A==
B<=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which only checks for exact zero.
Using '<=' or '<' which check for zero or less.
4fill in blank
hard

Fill both blanks to implement a method that removes a quantity of an item safely.

HLD
def remove_item(self, item_id, quantity):
    if self.stock.get(item_id, 0) [1] quantity:
        self.stock[item_id] [2] quantity
        return True
    return False
Drag options to blanks, or click blank then click option'
A>=
B<
C-=
D+=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' to check stock which is incorrect logic.
Using '+=' to remove stock which increases it.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that lists items with low stock.

HLD
threshold = {{BLANK_3}}
low_stock = {item: qty for item, qty in self.stock.items() if qty [1] threshold}
Drag options to blanks, or click blank then click option'
A<
B10
C<=
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' or '>' which finds high stock instead.
Confusing threshold values or operators.