Layover Experiences
AirbnbPhone screenMedium
You have a layover of total_hours hours and want to fill it with experiences. experiences[i] is how long experience i takes, in hours. Every duration and the layover length are rounded to a single decimal, such as 3.0 or 2.5.
You want to book as few experiences as possible, and you must use every hour of the layover. You may book the same experience as many times as you like. If no combination of bookings adds up to exactly total_hours, you book nothing and wait at the airport.
Write min_experiences(experiences, total_hours), which returns the smallest number of bookings whose durations sum to exactly total_hours, or 0 when no such combination exists.
Part 1: Fewest bookings for an exact fill
For example, with experiences = [3.0, 2.0] and total_hours = 7.0, the answer is 3 (2.0 + 2.0 + 3.0). With experiences = [3.6, 2.0] and total_hours = 7.5, no combination fits exactly, so the answer is 0.
- Example 1
- experiences
[3,2]- total_hours
7- Output
3
Why: Two 2.0 hour experiences and one 3.0 hour experience fill 7.0 hours, and no two experiences do: 2.0 + 3.0 = 5.0 and 3.0 + 3.0 = 6.0 and 2.0 + 2.0 = 4.0 are too short and 3.0 + 3.0 + 3.0 = 9.0 is too long. The answer is 3.
- Example 2
- experiences
[3.6,2]- total_hours
7.5- Output
0
Why: Every combination of 3.6 and 2.0 misses 7.5 (3.6 + 3.6 = 7.2, 3.6 + 2.0 = 5.6, 2.0 * 4 = 8.0), so nothing is booked and the answer is 0.
Constraints
1 <= len(experiences) <= 300.1 <= experiences[i] <= 24.00.1 <= total_hours <= 100.0- Every duration and
total_hourshas exactly one decimal place or fewer