Previous Bus Departure
Updated
Problem 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 Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026