Determine Exact Layover Booking
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's competency in algorithmic problem solving, numerical precision handling, and combinatorial selection under exact equality constraints.
Constraints
- 0 <= len(durations) <= 100
- 0.0 <= target_hours <= 1000.0
- Each value in durations is positive
- Each duration and target_hours has at most one digit after the decimal point
Examples
Input: ([2.0, 3.6], 7.2)
Expected Output: True
Explanation: Book the 3.6-hour experience twice to get exactly 7.2 hours.
Input: ([2.5, 4.0], 6.5)
Expected Output: True
Explanation: Book one 2.5-hour experience and one 4.0-hour experience.
Input: ([1.5, 2.0], 4.2)
Expected Output: False
Explanation: Any sum formed from 1.5 and 2.0 hours will be a multiple of 0.5, so 4.2 cannot be reached exactly.
Input: ([], 0.0)
Expected Output: True
Explanation: Choosing no experiences gives a total of 0.0 hours.
Input: ([], 1.0)
Expected Output: False
Explanation: With no available experiences, a positive target cannot be formed.