Minimize exact layover bookings
Company: Airbnb
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates algorithmic problem-solving and numeric precision handling, specifically the ability to model exact-duration sums and minimize the number of bookings under strict equality constraints.
Constraints
- 0 <= len(durations) <= 200
- 0.0 <= X <= 1000.0
- Each duration is greater than 0 and has exactly one decimal place
- You may reuse any duration an unlimited number of times
Examples
Input: ([3.0, 2.0], 7.0)
Expected Output: 3
Explanation: Book durations 2.0, 2.0, and 3.0 to reach exactly 7.0 hours with 3 bookings.
Input: ([1.0, 3.0, 4.0], 6.0)
Expected Output: 2
Explanation: The best exact combination is 3.0 + 3.0 = 6.0, which uses 2 bookings.
Input: ([0.1, 0.2, 0.5], 0.7)
Expected Output: 2
Explanation: Using 0.2 + 0.5 reaches 0.7 exactly with only 2 bookings. This case checks decimal precision handling.
Input: ([2.2, 4.4], 3.3)
Expected Output: 0
Explanation: No combination of 2.2 and 4.4 can add up to exactly 3.3.
Input: ([], 5.0)
Expected Output: 0
Explanation: With no available experiences, it is impossible to reach 5.0 hours.