Minutes Until the Next Shuttle From an HH:MM Departure Schedule
Company: Capital One
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Online Assessment
Overview: A string-processing problem: given one day's shuttle departure times in HH:MM format, sorted chronologically, and the current time, return the minutes until the next departure as a string, or -1 when no shuttle remains that day. It tests time parsing, conversion to minutes and boundary handling.
Read the full Capital One Machine Learning Engineer interview experience this question came from
Constraints
- 1 <= len(schedule) <= 10^4
- schedule is sorted in non-decreasing order and may contain repeated times.
- Every time, including current_time, is a valid "HH:MM" string from "00:00" to "23:59".
Examples
Input: (['07:15', '08:00', '12:30', '18:45'], '08:10')
Expected Output: '260'
Explanation: Source example 1: 08:10 is 490 minutes and the next departure 12:30 is 750, so 750 - 490 = 260 (hour borrow from 08:10 to 12:30).
Input: (['07:15', '08:00', '12:30', '18:45'], '19:00')
Expected Output: '-1'
Explanation: Source example 2: the last departure 18:45 is before 19:00 and nothing wraps to the next day.
Hints
- Turn each "HH:MM" time into a single number, such as the minutes elapsed since midnight, so two times can be compared and subtracted directly.
- Only the earliest departure that is not earlier than current_time matters, and a departure exactly at current_time counts with a wait of 0.
- Nothing carries over past midnight: if every departure is earlier than current_time, the answer is "-1".