Wait Until the Next Bus
Updated
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.
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
Similar questions at other companies
- Theme Park Shuttle Wait TimeAirbnb · OAAirbnb interview questions
- Macaron Order with Set DiscountsShopify · OAShopify interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Book Reading EveningsGoogle · OAGoogle interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
- Lift Total TravelInfosys · OAInfosys interview questions
- Shell Command Counts with History ReferencesTikTok · OATikTok interview questions
- Count Dropped RequestsJP Morgan Chase · OAJP Morgan Chase interview questions
- Recursively Expanded Shell Command CountsHudson River Trading · OAHudson River Trading interview questions