FastPrepWait Until the Next Bus

Wait Until the Next Bus

Capital One logoCapital One● EasyFULLTIMEOA
Learn

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[]) → int

Examples

Example 1

currentTime = "09:10"departures = ["08:45","09:30","10:00"]return = 20

The first departure not earlier than 09:10 is 09:30.

Example 2

currentTime = "17:00"departures = ["12:00","17:00","16:30"]return = 0

A departure occurs at the current time.

Constraints

  • 1 <= departures.length <= 10^5.
  • Every time is a valid same-day HH:MM value.

More Capital One problems

See Capital One hiring insights
public int nextBusWait(String currentTime, String[] departures) {
  // write your code here
}
currentTime"09:10"
departures["08:45","09:30","10:00"]
expected20
Checking account…