Babysitter Quote with Hourly Rates
Updated
Problem statement
Calculate a babysitter quote when the hourly pay changes with the time of day.
For this exercise, assume hourlyRates has exactly twenty-four entries. Entry h is the hourly rate in cents from hour h up to, but not including, hour h + 1. This daily schedule repeats at midnight. The start and end are integer minutes after midnight.
Charge from startMinute up to, but not including, endMinute, written [startMinute, endMinute). If the end is earlier than the start, the end is on the next day. Equal endpoints mean a zero-length booking, not a full day. Each billed minute costs one-sixtieth of the hourly rate for that minute. Add these charges without rounding them separately. Then round the total up to a whole cent, once. Return that integer number of cents.
These time, overnight, proration and rounding rules are the complete pricing rules; no additional fees, minimum booking or discounts apply.
Function
babysitterQuote(startMinute: int, endMinute: int, hourlyRates: int[]) → intExamples
Example 1
startMinute = 60endMinute = 120hourlyRates = [1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200]return = 1200One whole hour at a flat rate.
Example 2
startMinute = 450endMinute = 510hourlyRates = [600,600,600,600,600,600,600,600,1200,1200,1200,1200,1200,1200,1200,1200,1800,1800,1800,1800,1800,1800,1800,1800]return = 900A quote straddles an hourly rate change.
Example 3
startMinute = 1410endMinute = 30hourlyRates = [600,600,600,600,600,600,600,600,1200,1200,1200,1200,1200,1200,1200,1200,1800,1800,1800,1800,1800,1800,1800,1800]return = 1200One hour across midnight at different rates.
Constraints
0 <= startMinute, endMinute < 1440.hourlyRates.length = 24.0 <= hourlyRates[h] <= 10000cents per hour.- The booking lasts from zero through
1439whole minutes. - All weighted sums and the returned quote fit a signed 32-bit integer.
More Upstart interview questions
- Maximum SubarrayONSITE INTERVIEW · Seen Oct 2026
- Buffet Day GainsOA · Seen Sep 2026
- Case-Insensitive Anagram CheckOA · Seen Sep 2026
- Filter Duplicates While Preserving OrderOA · Seen Sep 2026
- Scale Ingredient QuantitiesOA · Seen Sep 2026
- ABO Parent Genotype CombinationsOA · Seen Aug 2026
- Chunked Byte Stream ChecksumsOA · Seen Aug 2026
- Cluster Size on DiskOA · Seen Aug 2026
- Double Substitution DecryptionOA · Seen Aug 2026
- Add Drama to Text GroupsOA · Seen Jul 2026
Similar questions at other companies
- Finish Time of Fixed-Length CPU TasksGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Online Meeting Scheduler with Fixed RoomsUber · ONSITE INTERVIEWUber interview questions
- Delivery Cost TrackerRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Expected Value of Modified DiceJane Street · ONSITE INTERVIEWJane Street interview questions
- Fractional Share Inventory FlatteningRobinhood · PHONE SCREEN · ONSITE INTERVIEWRobinhood interview questions
- Reservoir Sampling with Recorded DrawsMeta · ONSITE INTERVIEWMeta interview questions
- Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
- Reservoir Sampling with Recorded DrawsStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
- Iterate Canonical IPv6 AddressesOpenAI · ONSITE INTERVIEWOpenAI interview questions
- UCB1 Multi-Armed Bandit TraceWayfair · ONSITE INTERVIEWWayfair interview questions