Bird
0
0
LLDsystem_design~10 mins

Reservation and hold system 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 method that reserves an item.

LLD
def reserve_item(self, item_id):
    if self.inventory.[1](item_id):
        self.inventory.remove(item_id)
        return True
    return False
Drag options to blanks, or click blank then click option'
Ais_available
Bcheck_availability
Chas_item
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that removes the item instead of checking availability.
2fill in blank
medium

Complete the code to hold an item for a user.

LLD
def hold_item(self, item_id, user_id):
    if self.inventory.[1](item_id):
        self.holds[item_id] = user_id
        return True
    return False
Drag options to blanks, or click blank then click option'
Ais_reserved
Bis_locked
Cis_held
Dis_available
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to hold an item that is already reserved or held.
3fill in blank
hard

Fix the error in the method that releases a hold on an item.

LLD
def release_hold(self, item_id):
    if item_id in self.holds:
        [1] self.holds[item_id]
        return True
    return False
Drag options to blanks, or click blank then click option'
Adelete
Bpop
Cremove
Ddiscard
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' which is a list method, not dictionary.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps item IDs to user IDs for all held items.

LLD
held_items = { [1]: [2] for [1], [2] in self.holds.items() }
Drag options to blanks, or click blank then click option'
Aitem_id
Buser_id
Ckey
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable name for both key and value.
5fill in blank
hard

Fill all three blanks to filter held items where the user ID matches and the hold is still valid.

LLD
valid_holds = { [1]: [2] for [1], [2] in self.holds.items() if self.is_hold_valid([3]) }
Drag options to blanks, or click blank then click option'
Aitem_id
Buser_id
Dhold_id
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong variable to the validity check function.