Reported December 2023
ZipRecruitergreedy

Minutes since the Latest Departed Bus

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

The ZipRecruiter OA from December 2023 looks like a time puzzle, but it's just a max-under-a-limit scan with string parsing on top. If you've got an invite and 48 hours, this is one of the friendlier ones. Convert each HH:MM to minutes, keep the largest value that's still at or before the current time, and subtract. Return -1 if nothing qualifies. No sorting needed, no tricks. The only way to lose points is a parsing slip or an off-by-one on the equal case. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you probably won't need it here.

The problem

Every value is a valid 24-hour HH:MM time on the same day. Among departures no later than current, find the latest and return how many minutes have elapsed since it. A departure exactly at current returns 0. Return -1 when no bus has departed yet.

Function
minutesSinceLatestBus(schedule: String[], current: String) → int

Examples
Example 1
schedule = ["08:00","09:30","12:00"]
current = "10:00"
return = 30
The 09:30 bus departed thirty minutes earlier.
Example 2
schedule = ["08:00"]
current = "08:00"
return = 0
An exact departure gives zero minutes.

Constraints
1 <= schedule.length <= 100000
Every time is exactly five characters in HH:MM form.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The reduction is simple. Turn every time into minutes since midnight using hours * 60 + minutes. Do the same for current. Then walk the schedule once and track the maximum departure that's less than or equal to current. Answer is current minus that max, or -1 if you never found one. That's O(n) time and O(1) space, and it handles 100000 entries without breaking a sweat. Sorting works but costs O(n log n) for no gain. Common pitfalls: using strict less-than, which breaks the exact-match case that must return 0. Comparing the raw strings works too since HH:MM is zero-padded, but converting to integers makes the subtraction clean. Don't wrap past midnight, since everything is the same day. If you freeze on the live OA, StealthCoder is the hedge that hands you this loop while you stay calm and finish.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Minutes since the Latest Departed 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 StealthCoder

Related leaked OAs

⏵ The honest play

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.

Minutes since the Latest Departed Bus FAQ

How hard is the ZipRecruiter minutesSinceLatestBus problem really?+

Easy. It's a single pass with a running maximum. The only real work is converting HH:MM to minutes. If you can split a string on the colon and compare integers, you can solve it in a few minutes. Spend your spare time on edge cases.

What's the trick to this problem?+

Track the largest departure time that's less than or equal to current. Don't sort. Convert to minutes since midnight, compare with less-than-or-equal, and subtract at the end. Initialize your best value to -1 so the no-bus case falls out naturally.

What edge cases should I test before submitting?+

Test a departure exactly equal to current, which must return 0. Test a schedule where every bus is later than current, which returns -1. Test a single-element schedule. Test unsorted input, since the examples look sorted but the statement doesn't promise it.

Can I compare the time strings directly instead of parsing?+

Yes for comparison, since every time is zero-padded five-character HH:MM and lexicographic order matches time order. But you still need minutes to compute the difference. Parsing everything up front to integers is cleaner and avoids mixing two approaches.

How do I prepare for this in 48 hours?+

Practice a few running-max and filter-then-pick problems, plus time-string parsing. Write this one from scratch twice and check the equal and no-match cases. That's enough. The pattern is greedy in spirit, but it's really one linear scan.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it