InterviewDB
Experience
Campsite Booking: Find Available Campsites Given Reservation Intervals
phone
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
- What is the interval overlap condition? Prove your predicate handles edge cases (adjacent days).
- If
nand reservations are large, what index structure speeds up availability queries? - Extend to return the site with the fewest total reserved days among available sites.
- 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
- What is the interval overlap condition? Prove your predicate handles edge cases (adjacent days).
- If
nand reservations are large, what index structure speeds up availability queries? - Extend to return the site with the fewest total reserved days among available sites.
- How would you write this as a SQL query using NOT EXISTS or a LEFT JOIN approach?
Free preview. Unlock all Applied Intuition questions →
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 .
More Applied Intuition Interview Questions
InterviewDB
Big Data Design: Architect a Scalable Pipeline for Petabyte-Scale Log Processing
InterviewDB
Applied Intuition SWE Phone - Encode String (Strings/Encoding)
InterviewDB
Applied Intuition SWE Phone - Formula Evaluation (Stack/Parsing)
InterviewDB
Group Coordinates: Cluster 2D Points by Proximity
InterviewDB
Job Monitor: Track Long-Running Jobs and Alert on Failures or Timeouts