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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Court Time Calculation
00:00
5 left

Court Time Calculation

MediumPython

Problem

Hudl Sportscode records player substitutions as timestamped events during a match. Given the players on court at the start, substitution events, and the final match timestamp, calculate the total number of seconds each player was on the court.

Formal Specification

Implement calculate_court_time(initial_players, events, end_time).

  • initial_players is a list of player ID strings on court at timestamp 0.
  • events is a list of events represented as [timestamp, player_id, action], where action is either "in" or "out".
  • Events may be in any order. Events with the same timestamp have no meaningful ordering because no time passes between them.
  • end_time is the nonnegative integer timestamp when the match ends.
  • Return a dictionary mapping every player appearing in initial_players or events to their total court time in seconds. Players who never enter must have a total of 0.

Assume all timestamps are integers in [0, end_time], the input describes valid substitutions, and a player cannot be both on and off the court at the same time.

Constraints

  • 1 <= len(initial_players) <= 10
  • 0 <= len(events) <= 10^5
  • 0 <= timestamp <= end_time <= 10^9
  • Each event has the form [timestamp, player_id, action].
  • The action is either "in" or "out".
  • Events describe valid substitutions.
  • Events at the same timestamp are simultaneous.

Function Signature

def calculate_court_time(initial_players, events, end_time):
Interviewer

Your question is Court Time Calculation. 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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.