PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates time arithmetic and handling of cyclic day-wrap boundary conditions along with parsing and comparison of timestamp lists, reflecting skills in correct edge-case reasoning and efficient data processing.

  • hard
  • Capital One
  • Coding & Algorithms
  • Machine Learning Engineer

Compute minutes since last train departure

Company: Capital One

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Take-home Project

You are given a daily train timetable as a list of departure times (24-hour format `HH:MM`). Given the current time (also `HH:MM`), find the **most recent departure time that is not later than the current time**, and return how many minutes have elapsed since that departure. If there is **no departure earlier than or equal to the current time** on the same day, treat it as wrapping to the **previous day’s last departure**. ### Input - `departures`: list of strings, each in `HH:MM` (not necessarily sorted) - `now`: string in `HH:MM` ### Output Return: - `last_departure`: the departure time (as `HH:MM`) that most recently occurred relative to `now` - `minutes_ago`: the number of minutes between `last_departure` and `now` ### Example - `departures = ["01:10", "03:20", "05:20"]`, `now = "03:40"` - `last_departure = "03:20"`, `minutes_ago = 20` ### Constraints (assume typical interview constraints) - `1 <= len(departures) <= 10^5` - Times are valid and within a 24-hour day.

Quick Answer: This question evaluates time arithmetic and handling of cyclic day-wrap boundary conditions along with parsing and comparison of timestamp lists, reflecting skills in correct edge-case reasoning and efficient data processing.

Given daily departure times and current time, return the most recent departure not later than now, wrapping to previous day when needed.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: (['01:10','03:20','05:20'], '03:40')

Expected Output: {'last_departure': '03:20', 'minutes_ago': 20}

Explanation: Prompt example.

Input: (['23:50','00:10'], '00:05')

Expected Output: {'last_departure': '23:50', 'minutes_ago': 15}

Explanation: Wrap to previous day.

Input: (['12:00'], '12:00')

Expected Output: {'last_departure': '12:00', 'minutes_ago': 0}

Explanation: Exact departure.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Solve Four Coding Assessment Tasks - Capital One (medium)
  • Write SQL using joins and window functions - Capital One (medium)
  • Review Preprocessing Code and Tests - Capital One (easy)
  • Remove nodes with a given value - Capital One (medium)
  • Solve multiple algorithmic interview questions - Capital One (hard)