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
Implement Deterministic Workflow Scheduling
00:00
5 left

Implement Deterministic Workflow Scheduling

HardPython

Problem

Databricks Workflows executes tasks whose dependencies form a directed acyclic graph. Implement a scheduler that produces a deterministic execution order and computes the earliest completion time for every task when unlimited parallel execution is available.

A task can start only after all of its prerequisites finish. When multiple tasks are ready, choose the lexicographically smallest task ID. If the dependency graph contains a cycle, no valid schedule exists.

Formal Specification

Implement schedule_workflow(tasks, dependencies).

  • tasks is a dictionary mapping a unique string task ID to a nonnegative integer duration.
  • dependencies is a list of two-element lists [prerequisite, dependent].
  • Each dependency means prerequisite must finish before dependent starts.
  • Return None if the graph contains a cycle.
  • Otherwise, return a dictionary with:
    • order: the deterministic topological order of task IDs.
    • finish_times: a dictionary mapping each task ID to its earliest finish time.
    • makespan: the earliest time at which all tasks finish.

Tasks with no prerequisites start at time zero. The scheduler must not mutate its inputs.

Constraints

  • 1 <= len(tasks) <= 10^5
  • 0 <= len(dependencies) <= 2 * 10^5
  • Task IDs are unique strings with length from 1 to 50
  • Dependency endpoints always exist in tasks
  • Duplicate dependency pairs do not appear
  • Task durations are nonnegative integers

Function Signature

def schedule_workflow(tasks, dependencies):
Interviewer

Your question is Implement Deterministic Workflow Scheduling. 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.