Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Task Ordering with Dependencies

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

Your question is Task Ordering with Dependencies. 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 list of task names tasks and a list of dependency pairs dependencies, return a valid execution order of all tasks. Each dependency [a, b] means task a must be completed before task b. If no valid ordering exists because the dependency graph contains a cycle, return an empty list.

Constraints

  • 1 <= len(tasks) <= 10^4
  • 0 <= len(dependencies) <= 2 * 10^4
  • Task names are unique strings
  • Every dependency references a task in tasks

Function Signature

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