FastPrepBabysitter Quote with Hourly Rates

Babysitter Quote with Hourly Rates

Upstart logoUpstart● MediumFULLTIMEONSITE INTERVIEW
Learn

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 for the half-open interval from hour h through hour h + 1. This daily schedule repeats at midnight. The start and end are integer minutes after midnight.

Charge for the half-open interval [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 contributes one-sixtieth of its hourly rate. Add all exact minute charges, then round the total up to the next whole cent once. Return that integer number of cents.

These time, overnight, proration and rounding rules are explicit practice assumptions; no additional fees, minimum booking or discounts apply.

Function

babysitterQuote(startMinute: int, endMinute: int, hourlyRates: int[]) → int

Examples

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 = 1200

One 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 = 900

A 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 = 1200

One hour across midnight at different rates.

Constraints

  • 0 <= startMinute, endMinute < 1440.
  • hourlyRates.length = 24.
  • 0 <= hourlyRates[h] <= 10000 cents per hour.
  • The booking lasts from zero through 1439 whole minutes.
  • All weighted sums and the returned quote fit a signed 32-bit integer.

More Upstart problems

See Upstart hiring insights
public int babysitterQuote(int startMinute, int endMinute, int[] hourlyRates) {
    // Write your code here.
}
startMinute60
endMinute120
hourlyRates[1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200,1200]
expected1200
Checking account…