Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Closest Past Departure Time

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Closest Past Departure Time. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Circle's payout scheduler stores same-day departure times as strings in HH:MM format. Given an unsorted list of departure times and the current time, return how many minutes ago the closest departure at or before the current time occurred.

If no departure has occurred yet, return -1. Treat all times as occurring on the same day. Do not wrap around midnight, and do not select a departure after the current time.

Formal Specification

Implement find_latest_departure(departures, current_time):

  1. departures is a list of strings, where each string has the format HH:MM.
  2. current_time is a string in the same format.
  3. Convert every time to minutes after midnight.
  4. Find the largest departure time less than or equal to the current time.
  5. Return current_minutes - departure_minutes, or -1 if no valid departure exists.

Constraints

  • 0 <= len(departures) <= 10^5
  • Each time is valid and formatted as HH:MM
  • 00 <= HH <= 23 and 00 <= MM <= 59
  • The input list is unsorted
  • Duplicate departure times may appear
  • All times refer to the same day

Function Signature

def find_latest_departure(departures, current_time):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output