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
Time Window Overlap Function
00:00
5 left

Time Window Overlap Function

MediumPython

Problem

SoFi may need to find times when both a member and a financial specialist are available for an appointment. Given two lists of available time windows, return every time window when both schedules are open.

Each window is represented as a two-element list [start, end] and follows half-open interval semantics: it includes start but excludes end. The input lists are sorted by start time, and windows within each list do not overlap. Return the shared windows in chronological order. A shared window must have positive duration, so touching windows such as [10, 12] and [12, 15] do not overlap.

Formal Specification

Implement find_shared_openings(schedule_a, schedule_b):

  • Input: two lists of integer intervals, where each interval is [start, end] and start < end.
  • Output: a list of intervals representing the intersections between the two schedules.
  • Do not modify either input list.

Examples

Example 1

schedule_a = [[9, 12], [13, 17]]
schedule_b = [[10, 11], [11, 14], [16, 18]]
Output: [[10, 11], [11, 12], [13, 14], [16, 17]]

Each output interval is a period contained in one window from each schedule.

Example 2

schedule_a = [[8, 10], [12, 13]]
schedule_b = [[10, 12]]
Output: []

The windows only touch at boundaries, so there is no positive-length overlap.

Constraints

  • Each schedule contains at most 10^5 windows.
  • All times are integers from 0 through 10^9.
  • Each schedule is sorted and internally non-overlapping.
  • The result may contain at most len(schedule_a) + len(schedule_b) - 1 windows.

Constraints

  • 0 <= len(schedule_a), len(schedule_b) <= 10^5
  • Each interval has the form [start, end] with start < end
  • 0 <= start < end <= 10^9
  • Each schedule is sorted by start time
  • Windows within each schedule do not overlap
  • Touching intervals do not produce an output interval

Function Signature

def find_shared_openings(schedule_a, schedule_b):
Interviewer

Your question is Time Window Overlap Function. 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.