0
0
LLDsystem_design~10 mins

Inventory management in LLD - 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 class representing an inventory item.

LLD
class InventoryItem:
    def __init__(self, [1], quantity):
        self.[1] = [1]
        self.quantity = quantity
Drag options to blanks, or click blank then click option'
Astock
Blocation
Citem_id
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stock' instead of an identifier
Using 'price' which is not an identifier
Using 'location' which is unrelated here
2fill in blank
medium

Complete the code to add stock to the inventory item.

LLD
def add_stock(self, [1]):
    self.quantity += [1]
Drag options to blanks, or click blank then click option'
Aamount
Bitem
Cstock
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'item' which is confusing
Using 'stock' which is ambiguous
Using 'count' which is less clear
3fill in blank
hard

Fix the error in the method to remove stock safely.

LLD
def remove_stock(self, amount):
    if self.quantity [1] amount:
        self.quantity -= amount
    else:
        raise ValueError('Not enough stock')
Drag options to blanks, or click blank then click option'
A>
B>=
C<
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which allows removing more than available
Using '<=' which disallows removing all stock
Using '>' which disallows removing equal amount
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps item IDs to quantities for items with quantity greater than 0.

LLD
stock_map = {item.[1]: item.[2] for item in inventory if item.quantity > 0}
Drag options to blanks, or click blank then click option'
Aitem_id
Bquantity
Cprice
Dlocation
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'price' or 'location' which are unrelated
Swapping keys and values
5fill in blank
hard

Fill all three blanks to create a method that returns a list of item IDs with quantity below a threshold.

LLD
def low_stock_items(self, [1]):
    return [item.[2] for item in self.inventory if item.quantity [3] [1]]
Drag options to blanks, or click blank then click option'
Athreshold
Bitem_id
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' in the condition
Returning quantities instead of item IDs
Using wrong parameter name