Skip to content
Zeni Study
  • Pages
    • Learn Python In 7 Days
      • Day 1 : Variable + if/else
      • Day 2: Loops
      • Day 3 : Array + String
      • Day 4 — Functions
      • Day 5 — Dictionaries - Hashmap
      • Day 6 — Files & Errors
      • Day 7 — Mini Project & Programmer Thinking
    • Machine Coding:
      • Day 1 — Bank account + Wallet :
      • Day 2 : RateLimiter + seat booking
      • Day 3 : Library Management + Classroom Attendance System
      • Day 4 : Bank account and notification system.
      • Day 5 : Key-value and payment processor.
      • Day 6 : Discount engine + Seat booking( in depth)
      • Day 7: Parking lot System :
    • Machine coding extended:
      • Day 7.5 — Parking Lot (Constraint-Heavy Variant)
      • Day 8 : Order + Payment System
      • Day 8 — Extension Round (Mid-Interview Change)
      • Day 9 — Ticket Booking with Expiry (Simulated Time)
      • icon picker
        Day 9 — Extension Round (Seat Lock Ownership + Forced Unlock)
    • SQL + DB Thinking course
      • Day 1 — Tables, Rows & Thinking in Data
      • Day 2 — Relationships & Foreign Keys (Thinking in Connections)
      • Day 3 — Filtering, Aggregation & Answering Data Questions
      • Day 4 — JOINs (Combining Tables the Right Way)
      • Day 5 — Subqueries, EXISTS & NOT EXISTS (Thinking in Layers)
      • Day 6 — Indexes, Constraints & How Databases Think
      • Day 7 — Full SQL Interview Simulation (SDE-1 Ready)
      • Extended Day 1 — Core Business Systems (Deep Practice)
      • Extended Day 2 — Booking & Platform Systems (High-Depth Practice)
      • Extended Day 3 — Content & Learning Platforms (Capstone Practice)
    • LLD: Java
      • DAY 1 — Core Foundations (SDE-2 Level)
      • DAY 2 — State, Time & Domain Correctness
      • DAY 3 — Extensibility & Failure Handling (SDE-2 Core Signal)
      • DAY 4 — Concurrency, Scheduling & Consistency (SDE-2 Critical)
      • DAY 5 — Workflow Design & Config-Driven Systems (SDE-2+)
      • DAY 6 — Eventing & Usage-Based Systems (Advanced SDE-2)
      • DAY 7 — Interview Simulation (Hard, Production-Grade)
      • Hidden Edge Cases Interviewers Expect (Day-wise)
      • Detailed Testing file:
    • Assignment:
      • If else Practice Set

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

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

def unlock_if_expired(self, current_time: int) -> bool:
pass

def force_unlock(self, user_id: str) -> bool:
pass

def get_state(self) -> str:
pass
⚠️ Candidate must update existing implementation, not rewrite.

🧪 Extension Test File

📄 test_day9_extension.py

from solution import Seat


def test_lock_ownership():
print("Running lock ownership tests...")

seat = Seat("E1", lock_duration=5)

assert seat.lock(10, "user1") is True
assert seat.lock(11, "user2") is False

print("✅ Lock ownership tests passed")


def test_booking_by_owner_only():
print("Running booking ownership tests...")

seat = Seat("E2", lock_duration=5)

seat.lock(10, "user1")

assert seat.book(12, "user2") is False
assert seat.book(12, "user1") is True
assert seat.get_state() == "BOOKED"

print("✅ Booking ownership tests passed")


def test_force_unlock():
print("Running force unlock tests...")

seat = Seat("E3", lock_duration=5)

seat.lock(10, "user1")

assert seat.force_unlock("user2") is False
assert seat.force_unlock("user1") is True
assert seat.get_state() == "FREE"

print("✅ Force unlock tests passed")


def test_expiry_ignores_owner():
print("Running expiry ignores ownership tests...")

seat = Seat("E4", lock_duration=5)

seat.lock(10, "user1")

assert seat.unlock_if_expired(16) is True
assert seat.get_state() == "FREE"

print("✅ Expiry tests passed")


def test_no_actions_after_booked():
print("Running booked state tests...")

seat = Seat("E5", lock_duration=5)

seat.lock(10, "user1")
seat.book(12, "user1")

assert seat.force_unlock("user1") is False
assert seat.unlock_if_expired(20) is False
assert seat.lock(21, "user2") is False

print("✅ Booked state tests passed")


if __name__ == "__main__":
test_lock_ownership()
test_booking_by_owner_only()
test_force_unlock()
test_expiry_ignores_owner()
test_no_actions_after_booked()

print("\n🎉 ALL DAY 9 EXTENSION TESTS PASSED SUCCESSFULLY")

✅ Pass Criteria for Day 9 Extension

Candidate passes if:
All original Day 9 tests pass
All extension tests pass
Ownership enforced correctly
Expiry logic preserved
 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.