Minutes Until the Next Bus From a Daily Departure Schedule

Quick Overview

Given one day's bus departure times as HH:MM strings and the current time, return how many minutes remain until the next departure, or -1 when no bus is left that day. Tests time parsing, handling of unsorted and duplicate schedule entries, and exact boundary rules such as a bus leaving right now.

Minutes Until the Next Bus From a Daily Departure Schedule

Company: Capital One

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Online Assessment

A bus stop publishes the departure time of every bus for one day. Given that schedule and the current time, return how many minutes you have to wait until the next bus departs. ### Function Signature ```python def minutes_until_next_bus(schedule: list[str], current_time: str) -> int: ``` ### Rules - Every time, in `schedule` and in `current_time`, is a 24-hour clock string `HH:MM`: a two-digit hour from `00` to `23`, a colon, and a two-digit minute from `00` to `59`. - A bus that departs exactly at `current_time` can still be caught, so the wait is `0`. - The schedule covers a single day and does not repeat. Only departures at or after `current_time` on the same day count; if there are none, return `-1`. - `schedule` may be in any order and may list the same time more than once. - Return the wait as a whole number of minutes. ### Constraints - `1 <= len(schedule) <= 10^4` - Every time lies between `00:00` and `23:59` inclusive. - The answer is `-1` or an integer from `0` to `1439`. ### Examples **Example 1** ```text Input: schedule = ["08:00", "12:30", "17:45"], current_time = "11:50" Output: 40 ``` The next departure is `12:30`, which is 40 minutes after `11:50`. **Example 2** ```text Input: schedule = ["09:15", "06:40", "06:40"], current_time = "06:40" Output: 0 ``` A bus leaves at exactly the current time. **Example 3** ```text Input: schedule = ["07:00", "21:30"], current_time = "22:00" Output: -1 ``` Every bus has already left for the day.

Overview: Given one day's bus departure times as HH:MM strings and the current time, return how many minutes remain until the next departure, or -1 when no bus is left that day. Tests time parsing, handling of unsorted and duplicate schedule entries, and exact boundary rules such as a bus leaving right now.

|Home/Coding & Algorithms/Capital One
Capital One logo
Capital One
Sep 10, 2026
hardSoftware EngineerOnline AssessmentCoding & Algorithms
0
0

A bus stop publishes the departure time of every bus for one day. Given that schedule and the current time, return how many minutes you have to wait until the next bus departs.

Function Signature

def minutes_until_next_bus(schedule: list[str], current_time: str) -> int:

Rules

  • Every time, in schedule and in current_time , is a 24-hour clock string HH:MM : a two-digit hour from 00 to 23 , a colon, and a two-digit minute from 00 to 59 .
  • A bus that departs exactly at current_time can still be caught, so the wait is 0 .
  • The schedule covers a single day and does not repeat. Only departures at or after current_time on the same day count; if there are none, return -1 .
  • schedule may be in any order and may list the same time more than once.
  • Return the wait as a whole number of minutes.

Constraints

  • 1 <= len(schedule) <= 10^4
  • Every time lies between 00:00 and 23:59 inclusive.
  • The answer is -1 or an integer from 0 to 1439 .

Examples

Example 1

Input:  schedule = ["08:00", "12:30", "17:45"], current_time = "11:50"
Output: 40

The next departure is 12:30, which is 40 minutes after 11:50.

Example 2

Input:  schedule = ["09:15", "06:40", "06:40"], current_time = "06:40"
Output: 0

A bus leaves at exactly the current time.

Example 3

Input:  schedule = ["07:00", "21:30"], current_time = "22:00"
Output: -1

Every bus has already left for the day.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...