Layover Experiences
Asked at Airbnb
Reported by the problem's creator, not verified
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.
Examples
Example 1
Input: experiences =
[3,2], total_hours =7Output:
3Explanation: 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
Input: experiences =
[3.6,2], total_hours =7.5Output:
0Explanation: 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.