Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Therapy Practice Coding Extension

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

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

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output