Cinema

whitehousechef·2025년 7월 7일

Premium Seat Pricing

  • Add different seat types (Regular, Premium, VIP) with different pricing Modify the seating map to show seat types with different symbols Update booking flow to calculate total cost * how to approach during interview

Here's how I'd approach this premium seat pricing feature during an interview:

1. Clarify Requirements First

  • Ask about seat type distribution: "How are premium seats typically distributed in a cinema? Are VIP seats in the back, premium in middle, regular in front?"
  • Pricing structure: "Are prices fixed per seat type, or do they vary by movie/time?"
  • Display requirements: "How should different seat types be visually distinguished in the seating map?"

2. Design Approach Discussion

"I see we have existing Cinema, Seat, Booking, and Strategies classes. Let me think through the extension..."

Option A: Extend Seat Class

class Seat:
    def __init__(self, row, col, seat_type=SeatType.REGULAR):
        self.seat_type = seat_type
        # existing properties...
    
    def get_price(self):
        return self.seat_type.price

Option B: Composition Pattern

class SeatType:
    def __init__(self, name, symbol, price):
        self.name = name
        self.symbol = symbol  # for display
        self.price = price

class Seat:
    def __init__(self, row, col, seat_type):
        self.seat_type = seat_type

"I prefer Option B because it's more flexible - we can easily add new seat types or modify pricing without changing the Seat class."

3. Integration Points

Cinema Class:

  • "I'd add a method to initialize seat types when creating the seating map"
  • "Maybe cinema.configure_seat_layout(seat_type_map) where we can specify which seats are which type"

Booking Class:

  • "Add calculate_total_cost() method that sums up prices of selected seats"
  • "Display total cost before confirmation"

Display Strategy:

  • "Update the seating map rendering to show different symbols (., #, $, *) for different seat types"
  • "Add a legend explaining the symbols"

4. Implementation Strategy

"I'd implement this incrementally:

  1. Create SeatType enum/class with the three types
  2. Modify Cinema initialization to accept seat type configuration
  3. Update Seat class to include seat type
  4. Modify booking workflow to calculate and display total cost
  5. Update display methods to show seat type symbols
  6. Add legend/pricing info to the UI

5. Edge Cases to Consider

  • "What if a seat type becomes unavailable?" - Need to handle seat type changes
  • "How do we handle partial bookings?" - If user selects mixed seat types
  • "Pricing changes during booking?" - Should we lock prices when booking starts?

6. Testing Strategy

"I'd want to test:

  • Seat type assignment works correctly
  • Price calculations are accurate
  • Visual display shows correct symbols
  • Booking flow handles mixed seat types
  • Edge cases like all premium seats being booked

1

My attempt

1) clarifying questions for requirements

  • How will the different seat types be arranged? Via user input
  • What are the prices for each seat type? 10 for Regular, 15 for Premium, 20 for VIP
  • How will the different seat types be represented as? With symbols
  • So every movie has to have a custom seattype layout? No, if not mentioned, default to regular seat types
  • How about test cases? Do I make them along the way or just test the functionality at the end? Make simple ones along the way

2) break down the problem

  • SeatType enum to represent those 3 classes, with price property and string property for representation

  • cinema: get_total_cost_per_booking(booking) but cannot be @Property cuz this method needs a paramter of booking and property cannot have a paramter, property of seat_cost(seat or row,col) I feel this property can go to seat class instead of cinema class. Also need to set the custom layout in the cinema initialiser if theres such user input so ill put that in the initialiser

  • display_service: need to change display seating map to
    if seat is available -> represent as the seattype symbol instead of dot
    update display_booking_info to add the total cost per booking

  • factory to include custom user input for seat types, else default to regular seat types

1. Clarify Requirements First (2-3 minutes)

Ask questions to understand the scope:

  • "How long should seat reservations last?"
  • "Do we need to handle concurrent users?"
  • "Should different seat types have different timeout periods?"
  • "Do we need persistence or is in-memory fine?"

2. Break Down the Problem (5 minutes)

Identify core components:

  • Entities: Theatre, Cinema, Seat, Reservation
  • Operations: Reserve, Confirm, Cancel, Expire
  • Data: Seat status, timestamps, timeouts
  • Constraints: Time limits, concurrency

3. Design High-Level Architecture (10 minutes)

Start with main classes and their relationships:

class Theatre:
    - manages multiple cinemas
    
class Cinema:
    - manages seats and reservations
    
class Seat:
    - represents physical seat
    
class SeatReservation:
    - handles timing and expiration

4. Identify Key Challenges (5 minutes)

  • Timing: How to track and expire reservations
  • Concurrency: Multiple users booking same seat
  • Cleanup: Removing expired reservations
  • State Management: Available → Reserved → Booked

5. Implement Core Methods (15-20 minutes)

Focus on the most important operations:

def reserve_seat(self, position: str, timeout_minutes: int = 10) -> bool:
    # 1. Check if seat exists and is available
    # 2. Create reservation with expiration time
    # 3. Update seat status
    # 4. Start cleanup timer if needed
    
def is_expired(self) -> bool:
    # Simple time comparison
    return datetime.now() > self.expires_at

6. Handle Edge Cases (5 minutes)

  • Expired reservations
  • Double booking attempts
  • Invalid seat positions
  • Timer cleanup

Interview-Specific Tips:

Start Simple, Then Extend

# First: Basic reservation
def reserve_seat(self, seat_id):
    if seat_id in self.available_seats:
        self.reserved_seats[seat_id] = datetime.now()
        return True
    return False

# Then: Add timeout
def reserve_seat(self, seat_id, timeout_minutes=10):
    # Add expiration logic
    
# Finally: Add cleanup
def _cleanup_expired_reservations(self):
    # Background cleanup

Think Out Loud

  • "I'm thinking we need a way to track expiration times..."
  • "For concurrent access, we might need locks or atomic operations..."
  • "Let me handle the edge case where someone tries to book an expired reservation..."

Show Trade-offs

  • Memory vs Performance: "We could store all reservations in memory for speed, but that uses more RAM"
  • Polling vs Events: "We could check for expired reservations every 30 seconds, or use event-driven expiration"
  • Granularity: "Should timeouts be per-seat or per-reservation?"

Common Interview Variations

  1. "Add concurrency handling" → Use locks or atomic operations
  2. "Scale to multiple servers" → Discuss distributed systems, Redis, etc.
  3. "Add seat types with different timeouts" → Extend the seat model
  4. "Add notification when reservation expires" → Observer pattern

Time Management Strategy

  • Minutes 1-5: Requirements and high-level design
  • Minutes 5-20: Core implementation
  • Minutes 20-25: Edge cases and optimizations
  • Minutes 25-30: Extensions and scaling discussion

What Interviewers Look For

  • Problem decomposition: Can you break complex problems into smaller parts?
  • Clean code: Readable, maintainable structure
  • Edge case handling: Do you think about what can go wrong?
  • Extensibility: Can your design handle new requirements?

Red Flags to Avoid

  • Starting to code immediately without clarifying requirements
  • Overengineering the first solution
  • Ignoring edge cases
  • Not explaining your thought process

Multiple movies feature

My approach:

1) clarifying questions:

  • What data does each movie have? movie title, duration, starttime, end date
  • what is the user flow now?
  • What data of movie do we need? all the showtimes once a searched movie title is entered

2) break down the problem:
understand that previous test cases will be disrupted
in cinema class, extract movie class that has those fields and cinema will have a [str,List[Movie]] where for a certain movie title, it will have the list of movie details

0개의 댓글