Skip to content

Day 9 — Extension Round (Seat Lock Ownership + Forced Unlock)

Perfect. Below is Day 9 — Extension Round, added on top of the base Day 9 (Ticket Booking with Expiry).
This mirrors a real interview move:
“Okay, your basic solution works. Now let’s extend it.”
This extension is hard but fair, still Level-1+, and extremely common in SDE-1 interviews.

🟢 Day 9 — Extension Round (Seat Lock Ownership + Forced Unlock)

⏱ Extension Rules (Tell Candidate Clearly)

⏰ Time for extension: 25–30 minutes
❌ Do NOT change existing method signatures
❌ Do NOT break existing Day 9 tests
❌ Do NOT use real time
❌ Do NOT add new public classes
✅ You MAY add new private variables
✅ You MAY add new public methods only if specified

🧩 Extension Requirement — Lock Ownership

New Business Requirement

Seat locks are now user-specific.
A seat lock belongs to a user
Only the same user can book the seat
Only the same user can unlock before expiry
Expiry unlock works for any user

🆕 New Concepts Introduced (Still Safe)

Lock ownership
User-based validation
Slightly more state
No new patterns

🧱 Updated Seat Rules

New Fields (Internal Only)

Seat must now track:
locked_byuser_id (or None)
lock_time (already exists)

🔄 Updated Behavior Rules

lock(current_time, user_id)

⚠️ Method signature changes ONLY for this method
def lock(self, current_time: int, user_id: str) -> bool:
Return True if:
Seat is FREE
Then:
State → LOCKED
Store lock_time
Store locked_by = user_id
Else return False.

book(current_time, user_id)

⚠️ Method signature changes ONLY for this method
def book(self, current_time: int, user_id: str) -> bool:
Return True if:
Seat is LOCKED
Lock is not expired
locked_by == user_id
Then:
State → BOOKED
Clear locked_by
Return True
Else return False.

unlock_if_expired(current_time)

UNCHANGED
Still unlocks regardless of user
Clears locked_by

🆕 force_unlock(user_id)

NEW METHOD — explicitly allowed
def force_unlock(self, user_id: str) -> bool:
Return True if:
Seat is LOCKED
locked_by == user_id
Then:
State → FREE
Clear lock_time
Clear locked_by
Return True
Else return False.

get_state()

UNCHANGED.

🧠 Expected Candidate Thinking

Candidate must realize:
Lock ownership is state
Booking is authorization + state
Expiry ignores ownership
Force unlock is controlled unlock
Must NOT break old expiry logic
This tests precision under change.

🧪 Updated solution.py (Candidate Modifies Existing)

class Seat:
def __init__(self, seat_id: str, lock_duration: int):
pass

def lock(self, current_time: int, user_id: str) -> bool:
pass

 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.