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.
More Visa problems
- Connected GroupsOA · Seen Jul 2026
- Perfect SubstringsOA · Seen Jul 2026
- Maximum Server Processing TimeOA · Seen Jul 2026
- Signal PingsOA · Seen Jul 2026
- Sum of Index-Ordered Pair DifferencesOA · Seen Jul 2026
- Minimum Cost to Attend Required CoursesOA · Seen Jul 2026
- Minimum Score of a Path Between CitiesOA · Seen Jul 2026
- Planning ProductionOA · Seen Jul 2026