coding
Medium
hash map
#1
1. Coding — Find the Most Booked Property
1. Background: Airbnb displays several rental listings for travelers, and understanding the popularity of these properties helps hosts maximize their bookings and visibility. This problem involves analyzing booking data to identify which property has been booked the most.
2. Problem statement: Given a list of 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.
3. Function/class signature:
- def most_booked_property(bookings: List[Tuple[int, int]]) -> int:
4. Example 1:
- Input: [(1, 101), (2, 102), (1, 103), (3, 104), (2, 105), (1, 106)]
- Output: 1
- Explanation: Property 1 is booked by users 101, 103, and 106 (3 bookings), while properties 2 and 3 are booked 2 and 1 times respectively.
5. Example 2:
- Input: [(1, 101), (2, 102), (3, 103), (2, 104), (1, 105), (3, 106), (1, 107)]
- Output: 1
- Explanation: Property 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.
6. Constraints:
- 1 <= len(bookings) <= 10^6
- 1 <= property_id, user_id <= 10^9
Want to practise this one?
Create a free account to open the full question and practise Airbnb questions with AI.
Sign up free
coding
Medium
database
#2
2. DATABASE — Count Underperforming Listings
1. Background: Airbnb constantly seeks to optimize its platform for hosts and guests. A key metric in this optimization is identifying underperforming listings. This approach directly affects overall customer satisfaction and revenue.
2. Problem statement: Given a list of listings 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.
3. Function signature: def count_underperforming_listings(listings: List[Tuple[int, int, float]], min_views: int, min_bookings: int, min_rating: float) -> int
4. Example 1:
Input: listings = [(100, 5, 4.5), (50, 3, 4.0), (20, 0, 3.5)], min_views = 30, min_bookings = 2, min_rating = 4.0
Output: 2
Explanation: The last two listings are underperforming as they either have less than 30 views, less than 2 bookings, or a rating below 4.0.
5. Example 2:
Input: listings = [(200, 15, 4.8), (150, 10, 3.0), (40, 1, 2.5)], min_views = 50, min_bookings = 5, min_rating = 3.5
Output: 1
Explanation: Only the last listing is underperforming based on the conditions specified.
6. Constraints:
- The listings array can contain between 1 and 10^4 entries.
- Each entry's views and bookings are non-negative integers.
- Ratings are floats ranging from 0.0 to 5.0.
coding
Medium
hash map
#3
3. Hash Map — Count Listings Based on Reviews
Background: Airbnb has a vast number of listings, each with varying numbers of reviews. Understanding review distributions helps improve listing quality and user satisfaction.
Problem statement: Given a list of reviews represented as strings where each review contains the
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.
Function/class signature:def count_reviews(reviews: List[str]) -> Dict[str, int]:
Example 1:- Input:
reviews = ["1: Great stay!", "1: Loved it!", "2: Not bad.", "1: Would come again."]
- Output:
{'1': 3, '2': 1}
- Explanation: Listing 1 has three reviews while listing 2 has one.
Example 2:- Input:
reviews = ["3: Awesome experience!", "3: Best place ever!", "2: Clean and nice."]
- Output:
{'3': 2, '2': 1}
- Explanation: Listing 3 has two reviews while listing 2 has one.
Constraints:- The number of reviews will be at most
10^5.
- Each review will consist of a valid
listing_id followed by text (up to 200 characters).
coding
Medium
caching
#4
4. Caching Underperforming Listings: Identify and cache underperforming listings on Airbnb
Background: Underperforming listings can significantly impact hosts' revenue and guest experiences. Identifying these listings allows Airbnb to provide tailored insights to hosts, enhancing their visibility and ultimately improving booking rates.
Problem statement: You are given a list of listings, where each listing contains its ID, average reviews over the past month, and number of views. Define a function that identifies listings which have received lower than average views compared to the total views of all listings and caches these listings for quick access.
Define the following method:
List[int] identify_underperforming_listings(listings: List[Tuple[int, int, int]]) -> List[int]
Example 1: Input:
listings = [(1, 5, 100), (2, 4, 50), (3, 3, 75)] Output:
[2, 3] Explanation: Listing 2 has 50 views, which is under the average of (100 + 50 + 75) / 3 = 75, and Listing 3 has 75 views, also under average.
Example 2: Input:
listings = [(1, 4, 200), (2, 3, 200), (3, 5, 300)] Output:
[] Explanation: All listings have views equal to or above the average.
Constraints: - For
listings, 1 ≤ number of listings ≤ 1000
- Each listing has a unique ID that is an integer from 1 to 10^6
- Review score is an integer from 1 to 5
- View count is a non-negative integer up to 10000
coding
Medium
hash map
#5
5. Hash Map — Finding Underperforming Listings
Background: Airbnb depends on optimizing the performance of property listings to enhance user experiences and maximize revenue. Identifying underperforming listings can significantly aid in improving the marketplace.
Problem statement: Given a list of
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.
Function/class signature:def find_underperforming_listings(listings: List[Dict[str, int]], threshold: float) -> List[int]:
Example 1: Input:
find_underperforming_listings([{ 'id': 1, 'views': 100, 'bookings': 5 }, { 'id': 2, 'views': 200, 'bookings': 1 }, { 'id': 3, 'views': 50, 'bookings': 8 }], 0.1) Output:
[2] Explanation: Listing 2 has a bookings/views ratio of
0.005 which is below the threshold
0.1.
Example 2: Input:
find_underperforming_listings([{ 'id': 1, 'views': 300, 'bookings': 30 }, { 'id': 2, 'views': 150, 'bookings': 20 }], 0.1) Output:
[] Explanation: Both listings meet the threshold for performance.
Constraints:1 <= len(listings) <= 10^4
0 <= views, bookings <= 10000
0 < threshold <= 1
coding
Medium
hash map
#6
6. Hash Map — Detect underperforming listings based on rating and booking counts
Background: Airbnb relies on accurate metrics to enhance user experiences and optimize listings' visibility. Identifying underperforming listings can help improve the offerings and marketing strategies.
Problem statement: You are tasked with determining the
underperforming listings given a dataset of listings. Each listing has associated
ratings and
booking counts. A listing is considered underperforming if its
average rating is less than
4.0 and it has fewer than
10 bookings. You must implement a function that evaluates this and returns a list of listing IDs that meet these criteria.
Function/class signature:
def detect_underperforming_listings(listings: List[Dict[str, Union[int, float]]]) -> List[int]:
Example 1:Input:
listings = [{'id': 1, 'rating': 3.5, 'bookings': 8}, {'id': 2, 'rating': 4.5, 'bookings': 15}, {'id': 3, 'rating': 3.9, 'bookings': 5}]Output:
[1, 3] Explanation: Listing IDs 1 and 3 are underperforming based on their ratings and booking counts.
Example 2:Input:
listings = [{'id': 4, 'rating': 4.2, 'bookings': 12}, {'id': 5, 'rating': 3.9, 'bookings': 10}, {'id': 6, 'rating': 3.8, 'bookings': 9}]Output:
[5, 6] Explanation: Listing IDs 5 and 6 do not reach the minimum criteria for ratings or bookings.
Constraints:- 1 <= Listings <= 1000
- Each listing ID is a unique integer.
- 0 <= bookings <= 1000
- 0.0 <= rating <= 5.0
coding
Medium
graph
#7
7. Graph — Identify and evaluate underperforming listings
Background: In Airbnb's marketplace, listings that fail to meet certain performance criteria can impact overall business health. Identifying and evaluating these listings are crucial for improving customer satisfaction and optimizing earnings for hosts.
Problem statement: Write a function
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.
Function/class signature:
def evaluate_underperforming_listings(listings: List[Dict[str, Union[int, float]]]) -> List[int]:
Example 1: Input:
[
{"id": 1, "rating": 4.5, "bookings": 10},
{"id": 2, "rating": 3.8, "bookings": 2},
{"id": 3, "rating": 4.0, "bookings": 0}
] Output:
[2, 3]
Explanation: Listing 2 has a rating below 4.0 and Listing 3 has fewer than 5 bookings, hence both are underperforming.
Example 2: Input:
[
{"id": 1, "rating": 4.2, "bookings": 12},
{"id": 2, "rating": 4.4, "bookings": 5},
{"id": 3, "rating": 3.9, "bookings": 4}
] Output:
[3]
Explanation: Only Listing 3 is underperforming based on the given metrics.
Constraints:1 <= len(listings) <= 1000
- Each listing contains a unique
id with a rating as a float and bookings as an integer.
0 <= bookings <= 100
0.0 <= rating <= 5.0