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
Therapy Practice Coding Extension
00:00
5 left

Therapy Practice Coding Extension

MediumPython

Problem

Headway needs to select a profitable daily schedule of therapy sessions for one clinician. Implement optimize_schedule(sessions) to choose a set of non-overlapping sessions with maximum total value.

A session is compatible with another when the earlier session's end time is less than or equal to the later session's start time. The clinician cannot attend overlapping sessions. If multiple schedules have the same maximum value, prefer the schedule produced by skipping the latest session considered during dynamic programming. Returning no sessions is valid.

Formal Specification

Input is a list of dictionaries. Each dictionary contains a unique string id, an integer start, an integer end, and a non-negative integer value. Return a list of selected session IDs in chronological order. The selected IDs must represent pairwise compatible sessions and maximize the sum of their values.

Constraints

  • 0 <= len(sessions) <= 10^5
  • 0 <= start < end <= 10^9
  • 0 <= value <= 10^9
  • Session IDs are unique strings
  • The input list may be unsorted

Function Signature

def optimize_schedule(sessions):
Interviewer

Your question is Therapy Practice Coding Extension. 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.