Minimum Wait until the Next Bus
Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The ZipRecruiter OA reported in October 2023 looks like a time-formatting problem, but it's really modular arithmetic on a 1440-minute clock. Convert every HH:MM string to minutes, subtract the current time, wrap around midnight, and take the smallest result. That's the whole question. The trap is in the edge cases and the formatting, not the algorithm. If your head goes blank under the timer, StealthCoder runs invisibly as a safety net on the live OA and hands you the solution. Most candidates won't need it here, but it's a cheap hedge.
The problem
Every time is a valid 24-hour HH:MM string. Buses repeat daily. Return the minimum forward wait from current to any scheduled departure, formatted as HH:MM. A bus departing now has wait 00:00; departures earlier today are considered on the next day. Function minimumBusWait(schedules: String[], current: String) → String Examples Example 1 schedules = ["12:00","13:00"] current = "12:30" return = "00:30" The next bus is 30 minutes away. Example 2 schedules = ["08:15","09:00"] current = "08:15" return = "00:00" A bus at the current time gives zero wait. Constraints 1 <= schedules.length <= 100000 All strings use exactly two hour digits, a colon, and two minute digits.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is one formula: wait = (bus - current + 1440) % 1440. That single modulo handles the next-day rule for you. A bus at the current time gives 0, so it wins automatically and you can return early. A bus earlier today gives a positive wrap-around value, which is exactly the next-day departure. Loop through all schedules once, track the minimum, and you're at O(n) with up to 100000 entries. No sorting needed. Pitfalls: forgetting the modulo and returning negative numbers, treating an equal time as 24 hours instead of 0, and skipping zero-padding on output. Format with minutes divided by 60 for hours and minutes mod 60, each padded to two digits. If you freeze on the wrap-around logic during the live OA, StealthCoder can show you the formula, but you can also just memorize the one line above.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Minimum Wait until the Next Bus cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass ZipRecruiter's OA.
ZipRecruiter reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Wait until the Next Bus FAQ
How hard is the ZipRecruiter Minimum Wait until the Next Bus problem?+
Easy. It's a single pass with one modulo expression. The difficulty is in details like zero-padded output and the equal-time case, not in the algorithm. If you can parse a string and use the % operator, you can solve it in a few minutes.
What's the trick to this problem?+
Convert times to minutes since midnight and compute (bus - current + 1440) % 1440. That handles buses already gone today by wrapping them to tomorrow, and a bus at the current time naturally gives 0. Take the minimum across all schedules.
Do I need to sort the schedules?+
No. Sorting costs O(n log n) and adds nothing. A single linear scan with a running minimum is enough, even at 100000 entries. You can break early if you hit a wait of 0, since nothing can beat it.
How do I format the answer as HH:MM?+
Take the minimum wait in minutes. Hours are wait divided by 60 using integer division, minutes are wait mod 60. Pad both to two digits. Since the wait is always under 1440, hours never exceed 23, so a simple padded format works.
How should I prepare for this in 48 hours?+
Practice string parsing and modular wrap-around on a 24-hour clock, then write this solution once from scratch. Test three cases: the bus is later today, the bus is exactly now, and the bus already left. If those pass, you're ready for the OA.