Reported December 2025
Visabinary search

Previous Bus Departure

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

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

The Visa OA reported in December 2025 hides its only real trap in one word: "strictly." Previous Bus Departure looks like a warm-up, and it is, but a naive solution that uses less-than-or-equal returns the bus leaving at exactly the current time and fails Example 2. The departures array is already sorted and the times are HH:MM strings, so you're doing a lookup, not real algorithm work. If you blank on the boundary or the string handling, StealthCoder is the invisible safety net running during the live assessment. Most candidates will finish this fast. The ones who don't usually missed the equality case.

The problem

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) → String

Examples
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:MM 24-hour format.
departures is sorted in chronological order.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The pattern is binary search on a sorted array, though a linear scan passes just as well if the input is small. Find the last index where departure < currentTime. Because HH:MM is zero-padded 24-hour format, plain string comparison matches chronological order, so you can skip parsing into minutes. If you do convert, use hours * 60 + minutes and stay consistent. The pitfall is the boundary: a bus at exactly currentTime must not count, so use strict less-than. Also handle the empty result and return the string "-1", not the integer. A clean approach is to scan from the end and return the first time that is strictly less, or run a lower-bound search and step back one index. If the live OA throws a variant and your head goes blank, StealthCoder can hand you the working solution without the proctor seeing anything.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Previous Bus Departure 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Visa's OA.

Visa reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Previous Bus Departure FAQ

What's the trick in Previous Bus Departure?+

Strict comparison. A bus departing at exactly currentTime doesn't count, so you need less-than, not less-than-or-equal. Example 2 tests exactly this. Get the boundary right and the rest is a simple lookup on a sorted array.

Do I need to convert HH:MM into minutes?+

Not necessarily. Zero-padded 24-hour strings compare correctly as plain strings, so "09:45" < "11:30" works. Converting to minutes is safe too. Just pick one approach and use it for both the departures and currentTime.

Should I use binary search or a linear scan?+

Either passes the logic. The array is sorted, so binary search gives O(log n) by finding the last index with a time below currentTime. A reverse linear scan is simpler and harder to botch. Pick whichever you can write without off-by-one errors.

What should I return when no bus qualifies?+

Return the string "-1", not the number -1. This happens when every departure is at or after currentTime, including when the only match is exactly equal. Check the return type in the function signature before you submit.

How do I prepare for this in 48 hours?+

Practice the last-element-less-than-target pattern on sorted arrays, in both binary search and reverse scan form. Then test three edge cases: currentTime equal to the first departure, after the last departure, and before everything. That covers nearly every failure here.

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

OA at Visa?
Invisible during screen share
Get it