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
Dependency Traversal Function
00:00
5 left

Dependency Traversal Function

MediumPython

Problem

Vanta control workflows can depend on other controls or prerequisite checks. Given a collection of control records and a desired control ID, return every transitive dependency in dependency-first order, followed by the desired ID itself.

Formal Specification

Implement get_dependency_order(records, desired_id).

  • records is a list of dictionaries. Each dictionary has a unique string id and a dependencies list containing string IDs.
  • Every dependency ID refers to another record in records.
  • desired_id is the ID of an existing record.
  • Return a list of IDs containing all records reachable from desired_id, with each ID appearing exactly once.
  • A dependency must appear before any record that depends on it.
  • If the reachable dependency graph contains a cycle, raise ValueError.

The input may contain records unrelated to desired_id; exclude them from the result.

Constraints

  • 1 <= len(records) <= 10^5
  • Each record has a unique non-empty string ID
  • The total number of dependency references is at most 2 * 10^5
  • Every dependency ID refers to a record in records
  • The reachable dependency graph is acyclic for valid non-error cases

Function Signature

def get_dependency_order(records, desired_id):
Interviewer

Your question is Dependency Traversal 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.