Wait Until the Next Bus
Problem statement
You are given a current time and a list of bus departure times for the same service day. Every time is a zero-padded 24-hour string in HH:MM format.
Return the number of minutes until the earliest departure that is at or after the current time. A bus departing exactly now has wait 0. Return -1 if every listed departure has already passed.
Function
nextBusWait(currentTime: String, departures: String[]) → intExamples
Example 1
currentTime = "09:10"departures = ["08:45","09:30","10:00"]return = 20The first departure not earlier than 09:10 is 09:30.
Example 2
currentTime = "17:00"departures = ["12:00","17:00","16:30"]return = 0A departure occurs at the current time.
Constraints
1 <= departures.length <= 10^5.- Every time is a valid same-day
HH:MMvalue.