Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Dependency Graph Build Order

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Dependency Graph Build Order. Start with the requirements on the right.

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.

Problem

The SoFi app is assembled from software components with prerequisite relationships. Given all components and their dependencies, return an order in which every component can be built after its prerequisites. If a circular dependency makes a complete build impossible, return an empty list.

Formal Specification

Implement build_order(components, dependencies).

  • components is a list of unique strings.
  • dependencies is a list of two-element lists [prerequisite, component], meaning prerequisite must appear earlier than component.
  • Return a list containing every component exactly once in a valid build order, or [] if no complete order exists.
  • Components without dependencies may appear anywhere that preserves all dependency rules. When multiple components are available, process them in their original order from components.

Constraints

  • 1 <= len(components) <= 10^4
  • 0 <= len(dependencies) <= 3 * 10^4
  • Every dependency references a component in components
  • Component names are unique, non-empty strings
  • Dependency pairs are unique and contain distinct components

Function Signature

def build_order(components, dependencies):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output