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
Lexicographically Smallest Deployment Order
00:00
5 left

Lexicographically Smallest Deployment Order

HardPython

Problem

Implement a small, functional deployment tool or script to handle a specific infrastructure task.

Implement deployment_order(services, dependencies), where services is an array of unique service names and dependencies is an array of pairs [service, prerequisite]. Return a valid deployment order that installs every prerequisite before its dependent, choosing the lexicographically smallest available service at each step; return an empty array if the dependencies contain a cycle.

Assume every dependency names a service in services.

Constraints

  • 1 <= services.length <= 1000
  • All service names are unique non-empty strings
  • 0 <= dependencies.length <= services.length * (services.length - 1)
  • Each dependency is a pair [service, prerequisite]
  • Every dependency names services from services
  • A dependency pair does not repeat

Function Signature

def deployment_order(services, dependencies):
Interviewer

Your question is Lexicographically Smallest Deployment Order. 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.