InterviewDB Experience

Campsite Booking: Find Available Campsites Given Reservation Intervals

Interview Experience

Problem

You manage a campground with n campsites. Reservations are stored as (site_id, start_day, end_day) (inclusive). Given a requested stay (start, end),

return the list of available site IDs sorted in ascending order.

python
def available_campsites(
    n: int,
    reservations: list[tuple[int, int, int]],  # (site_id, start, end)
    request_start: int,
    request_end: int
) -> list[int]:
    pass

**Input**:
  n = 4
  reservations = [(1,1,5),(1,8,10),(2,3,7),(3,1,3)]
  request_start = 4, request_end = 6
Output: [1, 4]
# Site 1: occupied days 1-5 overlaps [4,6] -> not available
# Site 2: occupied days 3-7 overlaps [4,6] -> not available
# Site 3: occupied days 1-3, no overlap with [4,6] -> available
# Site 4: no reservations -> available
# Sorted: [3, 4]
Corrected Output: [3, 4]

Follow-ups

  1. What is the interval overlap condition? Prove your predicate handles edge cases (adjacent days).
  2. If n and reservations are large, what index structure speeds up availability queries?
  3. Extend to return the site with the fewest total reserved days among available sites.
  4. How would you write this as a SQL query using NOT EXISTS or a LEFT JOIN approach?

Full Details

Problem

You manage a campground with n campsites. Reservations are stored as (site_id, start_day, end_day) (inclusive). Given a requested stay (start, end),

return the list of available site IDs sorted in ascending order.

python
def available_campsites(
    n: int,
    reservations: list[tuple[int, int, int]],  # (site_id, start, end)
    request_start: int,
    request_end: int
) -> list[int]:
    pass

**Input**:
  n = 4
  reservations = [(1,1,5),(1,8,10),(2,3,7),(3,1,3)]
  request_start = 4, request_end = 6
Output: [1, 4]
# Site 1: occupied days 1-5 overlaps [4,6] -> not available
# Site 2: occupied days 3-7 overlaps [4,6] -> not available
# Site 3: occupied days 1-3, no overlap with [4,6] -> available
# Site 4: no reservations -> available
# Sorted: [3, 4]
Corrected Output: [3, 4]

Follow-ups

  1. What is the interval overlap condition? Prove your predicate handles edge cases (adjacent days).
  2. If n and reservations are large, what index structure speeds up availability queries?
  3. Extend to return the site with the fewest total reserved days among available sites.
  4. How would you write this as a SQL query using NOT EXISTS or a LEFT JOIN approach?

About This Question

This is a candidate experience report from a applied intuition interview during the phone round.

It covers the following topics: Coding, Sql, Phone, Onsite .