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
Start free
Testable Code Under Deadlines
00:00
5 left

Testable Code Under Deadlines

HardPython

Problem

What is your process for writing testable, maintainable code when faced with tight deadlines?

For the hands-on portion, implement build_execution_order(tasks, dependencies) as a pure function. Return a deterministic ordering that respects every prerequisite, choosing the lexicographically smallest available task at each step. Return an empty array when the dependencies contain a cycle.

Input: an array of unique task strings and an array of dependency pairs [prerequisite, task]. Output: an array containing every task once, or an empty array for cyclic input.

Example 1: tasks = ["test", "code", "review"], dependencies = [["code", "test"], ["test", "review"]] returns ["code", "test", "review"].

Example 2: tasks = ["a", "b"], dependencies = [["a", "b"], ["b", "a"]] returns [].

Constraints

  • 1 <= tasks.length <= 500
  • Each task name is a unique non-empty string
  • 0 <= dependencies.length <= tasks.length * (tasks.length - 1)
  • Every dependency references task names in tasks
  • A dependency pair contains distinct task names

Function Signature

def build_execution_order(tasks, dependencies):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
CodePython 3
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.