Airbnb software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Question You are skiing down from the top of a mountain and want to maximize your score when you reach the finish. There are multiple routes you...
Input: Graph (nodes and edges)n, the sequence is defined as follows: - If n is...Input: Integer(s)Question You are in a maze that is represented as a grid of cells, where each cell is either empty (O) or blocked (X). You can move up, down,...
Question AirBnB has a need to support refunds for our customers in case of booking changes or cancellations.
Input: Listid, neighborhood, host_id, capacity, and nightly_price. All keys and values are strings; prices are dollar amounts with exactly two decimal places.neighborhood exactly equals the requested neighborhood are eligible. All input properties are already available for the requested dates, and each may be selected at most once.group_size. Minimize total capacity first, then the number of selected properties, then the lexicographically smallest sorted list of property IDs.optimize_properties(properties: list[dict[str, str]], neighborhood: str, group_size: int). The return type is up to the candidate; Example 1 uses a JSON array of IDs as its reference representation.{
"properties": [
{"id": "A", "neighborhood": "Mission", "host_id": "h1", "capacity": "4", "nightly_price": "70.00"},
{"id": "B", "neighborhood": "Mission", "host_id": "h2", "capacity": "3", "nightly_price": "50.00"},
{"id": "C", "neighborhood": "Mission", "host_id": "h3", "capacity": "7", "nightly_price": "150.00"},
{"id": "D", "neighborhood": "Sunset", "host_id": "h4", "capacity": "7", "nightly_price": "120.00"},
{"id": "E", "neighborhood": "Mission", "host_id": "h5", "capacity": "8", "nightly_price": "100.00"}
],
"neighborhood": "Mission",
"group_size": 7
}["C"]
A + B and C both provide exactly 7 places, but C uses one property instead of two. E provides 8 places, and D is ineligible because its neighborhood differs. Price is not an objective.Part 2 — Add traveler-supplied booking policiesoptimize_with_policies(properties: list[dict[str, str]], neighborhood: str, group_size: int, policies: list[dict[str, str]]). The return type remains your choice; the examples use a summary object.{"type": "nightly_budget", "limit": "120.00"}: the sum of selected nightly prices must be less than or equal to the limit. Use exact cents, not floating-point arithmetic.{"type": "host_limit", "limit": "1"}: select at most the specified number of properties from each host. This is a per-host limit, not a limit on the number of distinct hosts.ValueError.status: "OK", sorted property_ids, integer total_capacity, and total_nightly_price formatted with two decimal places. An impossible result contains status: "IMPOSSIBLE", an empty ID list, capacity 0, and price "0.00".{
"properties": [
{"id": "A", "neighborhood": "Mission", "host_id": "h1", "capacity": "4", "nightly_price": "70.00"},
{"id": "B", "neighborhood": "Mission", "host_id": "h2", "capacity": "3", "nightly_price": "50.00"},
{"id": "C", "neighborhood": "Mission", "host_id": "h3", "capacity": "7", "nightly_price": "150.00"},
{"id": "D", "neighborhood": "Sunset", "host_id": "h4", "capacity": "7", "nightly_price": "120.00"},
{"id": "E", "neighborhood": "Mission", "host_id": "h5", "capacity": "8", "nightly_price": "100.00"}
],
"neighborhood": "Mission",
"group_size": 7,
"policies": [
{"type": "nightly_budget", "limit": "120.00"},
{"type": "host_limit", "limit": "1"}
]
}{
"status": "OK",
"property_ids": ["A", "B"],
"total_capacity": 7,
"total_nightly_price": "120.00"
}A + B provides 4 + 3 = 7 places for 70.00 + 50.00 = 120.00, exactly the budget. Each selected host contributes one property, satisfying the host limit. C exceeds the budget by 30.00. E costs less but provides 8 places, so it loses on the primary objective.Example 3:{
"properties": [
{"id": "P", "neighborhood": "Mission", "host_id": "h1", "capacity": "4", "nightly_price": "60.00"},
{"id": "Q", "neighborhood": "Mission", "host_id": "h1", "capacity": "3", "nightly_price": "40.00"},
{"id": "R", "neighborhood": "Mission", "host_id": "h2", "capacity": "7", "nightly_price": "130.00"},
{"id": "S", "neighborhood": "Mission", "host_id": "h3", "capacity": "8", "nightly_price": "101.00"}
],
"neighborhood": "Mission",
"group_size": 7,
"policies": [
{"type": "nightly_budget", "limit": "100.00"},
{"type": "host_limit", "limit": "1"}
]
}{
"status": "IMPOSSIBLE",
"property_ids": [],
"total_capacity": 0,
"total_nightly_price": "0.00"
}P + Q provides 4 + 3 = 7 places for exactly 100.00, but selects two properties from h1, exceeding the limit of 1. R and S individually exceed the budget by 30.00 and 1.00. Adding either to another selection cannot reduce its cost. The selection P + Q + R breaks both policies: its price is 230.00 and its h1 count is 2. The only remaining feasible nonempty selections are P and Q, neither of which accommodates 7 guests.Notes:group_size is from 1 to 440. Exact optimization is required; explain why greedy selection is insufficient."0.00" to "10000.00"; a host limit is an integer string from "0" to "22". Except for unknown policy types, inputs satisfy the stated schema.id, a string neighborhood, and a positive integer capacity. All properties are available for the requested dates, and each property can be selected at most once.Select a subset of properties in target_neighborhood whose combined capacity is at least group_size. Optimize the selection in this order:1. Minimize total capacity while accommodating the entire group.group_size is zero. Neighborhood matching is case-sensitive, and travelers may be divided among selected properties without any additional restrictions.Function or class signatureoptimize_booking(properties: list[Property], target_neighborhood: str, group_size: int) -> list[int]Property has fields id: int, neighborhood: str, and capacity: int.{
"properties": [
{"id": 101, "neighborhood": "SoMa", "capacity": 6},
{"id": 102, "neighborhood": "SoMa", "capacity": 4},
{"id": 103, "neighborhood": "SoMa", "capacity": 10},
{"id": 104, "neighborhood": "SoMa", "capacity": 5},
{"id": 105, "neighborhood": "Mission", "capacity": 10}
],
"target_neighborhood": "SoMa",
"group_size": 10
}Output:[103]Explanation: Both
[101, 102] and [103] provide exactly 10 spaces. Property 103 wins because it uses one property instead of two. Property 105 is in the wrong neighborhood.Example 2:Input:{
"properties": [
{"id": 201, "neighborhood": "Mission", "capacity": 6},
{"id": 202, "neighborhood": "Mission", "capacity": 5},
{"id": 203, "neighborhood": "Mission", "capacity": 4},
{"id": 204, "neighborhood": "SoMa", "capacity": 8}
],
"target_neighborhood": "Mission",
"group_size": 8
}Output:[202, 203]Explanation: No eligible selection has total capacity 8. Properties 202 and 203 provide 9 spaces, which is better than the other feasible totals of 10, 11, and 15.Constraints:
0 <= len(properties) <= 2000.target_neighborhood.[1, 10^9].1 <= capacity <= 10^9.0 <= group_size <= 10^12.target_neighborhood are strings of length 1 through 100.bookings, where each booking is represented as a tuple (property_id, user_id), write a function that returns the property_id of the property that has the most bookings. If there are ties, return the property with the smallest property_id.def most_booked_property(bookings: List[Tuple[int, int]]) -> int:[(1, 101), (2, 102), (1, 103), (3, 104), (2, 105), (1, 106)] 1 1 is booked by users 101, 103, and 106 (3 bookings), while properties 2 and 3 are booked 2 and 1 times respectively.[(1, 101), (2, 102), (3, 103), (2, 104), (1, 105), (3, 106), (1, 107)] 1 1 is booked 3 times, while properties 2 and 3 are tied with 2 bookings each but we choose 1 because it has the most.1 <= len(bookings) <= 10^61 <= property_id, user_id <= 10^9listings with associated views, bookings, and ratings, determine how many listings are considered underperforming. A listing is classified as underperforming if it has fewer than min_views AND fewer than min_bookings AND a rating lower than min_rating.def count_underperforming_listings(listings: List[Tuple[int, int, float]], min_views: int, min_bookings: int, min_rating: float) -> intlistings = [(100, 5, 4.5), (50, 3, 4.0), (20, 0, 3.5)], min_views = 30, min_bookings = 2, min_rating = 4.0 2 listings = [(200, 15, 4.8), (150, 10, 3.0), (40, 1, 2.5)], min_views = 50, min_bookings = 5, min_rating = 3.5 1 listings array can contain between 1 and 10^4 entries. views and bookings are non-negative integers. listing_id, return a hash map (dictionary) that counts the number of reviews for each listing. Each review is structured as "listing_id: review content". The output should be a dictionary where the keys are listing_id and the values are the counts of reviews for that listing.def count_reviews(reviews: List[str]) -> Dict[str, int]:reviews = ["1: Great stay!", "1: Loved it!", "2: Not bad.", "1: Would come again."]{'1': 3, '2': 1}reviews = ["3: Awesome experience!", "3: Best place ever!", "2: Clean and nice."]{'3': 2, '2': 1}10^5.listing_id followed by text (up to 200 characters).List[int] identify_underperforming_listings(listings: List[Tuple[int, int, int]]) -> List[int]listings = [(1, 5, 100), (2, 4, 50), (3, 3, 75)] [2, 3] listings = [(1, 4, 200), (2, 3, 200), (3, 5, 300)] [] listings, 1 ≤ number of listings ≤ 1000 listings where each listing is a dictionary containing id, views, and bookings, implement a function to find listings that are considered *underperforming*. A listing is *underperforming* if its ratio of bookings to views is below a given threshold (e.g., 0.1). Return the IDs of the underperforming listings in ascending order.def find_underperforming_listings(listings: List[Dict[str, int]], threshold: float) -> List[int]:find_underperforming_listings([{ 'id': 1, 'views': 100, 'bookings': 5 }, { 'id': 2, 'views': 200, 'bookings': 1 }, { 'id': 3, 'views': 50, 'bookings': 8 }], 0.1) [2] 0.005 which is below the threshold 0.1. find_underperforming_listings([{ 'id': 1, 'views': 300, 'bookings': 30 }, { 'id': 2, 'views': 150, 'bookings': 20 }], 0.1) [] 1 <= len(listings) <= 10^40 <= views, bookings <= 100000 < threshold <= 1def detect_underperforming_listings(listings: List[Dict[str, Union[int, float]]]) -> List[int]:listings = [{'id': 1, 'rating': 3.5, 'bookings': 8}, {'id': 2, 'rating': 4.5, 'bookings': 15}, {'id': 3, 'rating': 3.9, 'bookings': 5}][1, 3] listings = [{'id': 4, 'rating': 4.2, 'bookings': 12}, {'id': 5, 'rating': 3.9, 'bookings': 10}, {'id': 6, 'rating': 3.8, 'bookings': 9}][5, 6] evaluate_underperforming_listings that takes a list of listings in the form of a dictionary and evaluates them against predefined performance metrics. A listing is considered underperforming if it has a rating below 4.0 or has fewer than 5 bookings. The function should return a list of listing IDs that are underperforming.def evaluate_underperforming_listings(listings: List[Dict[str, Union[int, float]]]) -> List[int]:[
{"id": 1, "rating": 4.5, "bookings": 10},
{"id": 2, "rating": 3.8, "bookings": 2},
{"id": 3, "rating": 4.0, "bookings": 0}
] [2, 3]
[
{"id": 1, "rating": 4.2, "bookings": 12},
{"id": 2, "rating": 4.4, "bookings": 5},
{"id": 3, "rating": 3.9, "bookings": 4}
] [3]
1 <= len(listings) <= 1000id with a rating as a float and bookings as an integer.0 <= bookings <= 1000.0 <= rating <= 5.0rental_id with their corresponding availability ranges in the form of pairs (start_date, end_date) and a queried date range, return a list of rental IDs that are available during the entire period of the query.def search_available_rentals(rentals: List[Tuple[int, Tuple[int, int]]], query: Tuple[int, int]) -> List[int]: - Returns rental IDs that are available for the entire query date range.1 <= rentals.length <= 10^41 <= rental_id <= 10^61 <= start_date < end_date <= 10^61 <= query[0] < query[1] <= 10^6property_id and a list of neighbors (i.e., directly connected properties).def find_neighbors(properties: List[Property], id: int, distance: int) -> List[int]: - Returns the list of property identifiers of neighboring properties within the specified distance.1 <= properties.length <= 10001 <= property_id <= 10^60 <= distance <= 50capacity. The cache should support get(key) and put(key, value) operations.class LRUCache:def __init__(self, capacity: int): - Initializes the LRUCache with the maximum capacity.def get(self, key: int) -> int: - Returns the value of the key if the key exists in the cache, otherwise return -1.def put(self, key: int, value: int): - Update the value of the key if it exists, otherwise add the key-value pair to the cache. When the cache reaches its capacity, it should invalidate the least recently used item before inserting a new item.1 <= capacity <= 30000 <= key <= 10^40 <= value <= 10^4Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free