Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Agent Workflow DAG

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

Your question is Validate Agent Workflow DAG. 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

Given a workflow of n steps labeled 0 to n - 1, a list of directed edges dependencies where [a, b] means step a must run before step b, a list required_tools where required_tools[i] contains the tool names needed by step i, and a set available_tools, write a function that validates the workflow before execution. Return whether the graph is acyclic and whether every step's required tools are available. If valid, also return one valid execution order; otherwise return the cycle nodes and the steps with missing tools.

Constraints

  • 1 <= n <= 10^5
  • 0 <= len(dependencies) <= 2 * 10^5
  • len(required_tools) == n
  • 0 <= len(required_tools[i]) <= 50
  • Step indices in dependencies are in the range [0, n - 1]

Function Signature

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