FastPrepMinutes since the Latest Departed Bus

Minutes since the Latest Departed Bus

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

Every value is a valid 24-hour HH:MM time on the same day. Among departures no later than current, find the latest and return how many minutes have elapsed since it. A departure exactly at current returns 0. Return -1 when no bus has departed yet.

Function

minutesSinceLatestBus(schedule: String[], current: String) → int

Examples

Example 1

schedule = ["08:00","09:30","12:00"]current = "10:00"return = 30

The 09:30 bus departed thirty minutes earlier.

Example 2

schedule = ["08:00"]current = "08:00"return = 0

An exact departure gives zero minutes.

Constraints

  • 1 <= schedule.length <= 100000
  • Every time is exactly five characters in HH:MM form.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int minutesSinceLatestBus(String[] schedule, String current) {
    // Write your code here.
}
schedule["08:00","09:30","12:00"]
current"10:00"
expected30
Checking account…