FastPrepMinimum Wait until the Next Bus

Minimum Wait until the Next Bus

ZipRecruiter logoZipRecruiter● EasyFULLTIMENEW GRADOA
Learn

Problem statement

Every time is a valid 24-hour HH:MM string. Buses repeat daily. Return the minimum forward wait from current to any scheduled departure, formatted as HH:MM. A bus departing now has wait 00:00; departures earlier today are considered on the next day.

Function

minimumBusWait(schedules: String[], current: String) → String

Examples

Example 1

schedules = ["12:00","13:00"]current = "12:30"return = "00:30"

The next bus is 30 minutes away.

Example 2

schedules = ["08:15","09:00"]current = "08:15"return = "00:00"

A bus at the current time gives zero wait.

Constraints

  • 1 <= schedules.length <= 100000
  • All strings use exactly two hour digits, a colon, and two minute digits.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String minimumBusWait(String[] schedules, String current) {
    // Write your code here.
}
schedules["12:00","13:00"]
current"12:30"
expected"00:30"
Checking account…