Reported September 2026
Capital Onearray

Wait Until the Next Bus

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

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

The Capital One OA reported in September 2026 looks like a bus schedule story, but it's really a minimum-over-a-filter problem. Convert every HH:MM string to minutes, keep the ones at or after now, and return the smallest gap. If you've got an invite in your inbox, this is the easy end of the pool. The trap isn't the algorithm. It's the parsing, the off-by-one on equality, and the -1 case. If you blank on the live assessment, StealthCoder runs invisibly as a safety net, but you probably won't need it for this one.

The problem

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[]) → int

Examples
Example 1
currentTime = "09:10"
departures = ["08:45","09:30","10:00"]
return = 20
The first departure not earlier than 09:10 is 09:30.
Example 2
currentTime = "17:00"
departures = ["12:00","17:00","16:30"]
return = 0
A departure occurs at the current time.

Constraints
1 <= departures.length <= 10^5.
Every time is a valid same-day HH:MM value.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: one pass, no sorting needed. Parse each string into minutes with hours * 60 + minutes. Compute diff = dep - now. If diff >= 0, track the minimum. After the loop, return the minimum, or -1 if you never found a valid departure. The departures list isn't guaranteed sorted (example 2 shows 16:30 after 17:00), so don't assume order and don't binary search without sorting first. Sorting works but costs O(n log n) for no gain at 10^5 items. Linear scan is O(n) time and O(1) space. The common pitfalls are using > instead of >= and missing the wait of 0 case, and comparing strings lexicographically then subtracting wrongly. Zero-padded strings do compare correctly as text, but you still need minutes for the answer. Also initialize the minimum to a sentinel like infinity, not 0. StealthCoder is the hedge if your mind goes blank on the live OA, but the logic here fits in about ten lines.

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 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 StealthCoder

Related leaked OAs

⏵ The honest play

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

Capital One 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.

Wait Until the Next Bus FAQ

How hard is the Capital One Wait Until the Next Bus problem really?+

Easy. It's a single pass with time parsing. The difficulty is in details: inclusive comparison for a bus leaving exactly now, unsorted input, and returning -1 when nothing remains. If you can write a loop with a running minimum, you can solve this.

What's the trick to solve it fast?+

Convert HH:MM to total minutes, subtract the current time, and ignore negative differences. Track the smallest non-negative difference. Return -1 if none was found. No sorting, no binary search, no data structures needed.

Do I need to sort the departures array?+

No. The input can be unordered, as example 2 shows. Sorting then binary searching works at O(n log n), but a linear scan at O(n) is simpler and faster for 10^5 entries. Less code also means fewer bugs under pressure.

What edge cases should I test before submitting?+

Test a departure exactly equal to the current time, which must return 0. Test all departures earlier than now, which must return -1. Test a single-element list. Test 00:00 and 23:59 boundaries. Also confirm your sentinel isn't colliding with a valid wait value.

How do I prepare for this in 48 hours?+

Write the solution once from scratch in your OA language, including a small helper to parse HH:MM. Then run the two examples plus the edge cases. Spend the rest of your time on medium array and hash map problems, since the OA may include harder questions than this.

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

OA at Capital One?
Invisible during screen share
Get it