Problem
Previous Bus Departure
Learn this problemProblem statement
You are given an array departures of bus departure times in chronological order. Each time is in HH:MM 24-hour format.
You are also given the current time currentTime in the same format. Return the departure time of the latest bus that departed strictly before currentTime. If no bus departed before currentTime, return "-1".
Function
previousBusDeparture(departures: String[], currentTime: String) → StringExamples
Example 1
departures = ["08:15", "09:45", "11:30", "14:00"]currentTime = "12:00"return = "11:30"The latest departure strictly before 12:00 is 11:30.
Example 2
departures = ["08:15", "09:45"]currentTime = "08:15"return = "-1"A bus at exactly currentTime is not before the current time, and there is no earlier departure.
Constraints
- Each time string is in
HH:MM24-hour format. departuresis sorted in chronological order.