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
Detect Cycles in Pipeline Graph
00:00
5 left

Detect Cycles in Pipeline Graph

EasyPython

Problem

Roku data pipelines can depend on one another, and a circular dependency prevents the pipeline schedule from completing. Given a directed dependency graph, determine whether it contains at least one cycle.

Use depth-first search with three states for each node: unvisited, currently visiting, and fully processed.

Formal Specification

Implement detect_cycle(graph), where graph is a dictionary mapping each pipeline name to a list of pipeline names that must run after it. A referenced pipeline may appear only in an adjacency list and does not need its own dictionary entry. Return True if the directed graph contains a cycle; otherwise, return False.

Constraints

  • 0 <= number of declared nodes <= 10^5
  • 0 <= number of edges <= 2 * 10^5
  • Node names are non-empty strings
  • The graph may be disconnected
  • A referenced node may be absent as a dictionary key

Function Signature

def detect_cycle(graph):
Interviewer

Your question is Detect Cycles in Pipeline Graph. 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.