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
Python Helper Function Implementation
00:00
5 left

Python Helper Function Implementation

MediumPython

Problem

General Dynamics Land Systems mission software may represent an Abrams vehicle procedure as a recipe of named steps. Each step lists the steps that must finish before it can begin. Implement a helper that groups the recipe into execution batches, where every step in a batch can run concurrently and batches execute in order.

Return the batches in deterministic order by sorting step names alphabetically within each batch. Return an empty list if the recipe contains a dependency cycle.

Formal Specification

Implement schedule_recipe(steps), where steps is a dictionary mapping a step name to a list of prerequisite step names. Every prerequisite appears as a key in steps. Return a list of lists of strings. Each inner list is one executable batch.

Constraints

  • 1 <= len(steps) <= 10^4
  • Step names are unique non-empty strings
  • Every prerequisite appears as a key in steps
  • The total number of dependency relationships is at most 5 * 10^4
  • Return [] when the dependency graph contains a cycle

Function Signature

def schedule_recipe(steps):
Interviewer

Your question is Python Helper Function Implementation. 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.