Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Subway Check-In Rules
00:00
5 left

Subway Check-In Rules

EasyPython

Problem

The Oscar Health member app records visit times for each member. Given a member's visit history and a proposed check-in time, determine whether the member can check in. A check-in is allowed only when the member has no earlier visit or at least 15 minutes have elapsed since their most recent visit.

Formal Specification

Implement can_check_in(visit_times, user_id, check_in_time), where visit_times is a dictionary mapping user IDs to sorted lists of integer timestamps, measured in minutes. Return a Boolean. Consider only visits at or before check_in_time; future visits must not affect the result. A member may check in exactly 15 minutes after the previous visit.

Constraints

  • 0 <= len(visit_times[user_id]) <= 10^5
  • Each user's timestamps are sorted in nondecreasing order
  • 0 <= timestamps and check_in_time <= 10^9
  • user_id may be absent from visit_times
  • The cooldown is exactly 15 minutes

Function Signature

def can_check_in(visit_times, user_id, check_in_time):
Interviewer

Your question is Subway Check-In Rules. Start with the requirements in the Question tab.

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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.