⚡️ Tryprepforge
Backend Engineer Senior programming

You need to implement a function that determines if a sequence of tasks can be completed based on given dependencies between them. Each task is represented by a unique integer ID. You must return a valid order of tasks if possible, or an empty list if not. **Function Signature:** `def task_order(tasks: List[int], dependencies: List[Tuple[int, int]]) -> List[int]:` **Constraints:** - `1 <= len(tasks) <= 1000` - `len(dependencies) <= 10^4` **Example 1:** Input: `tasks = [1, 2, 3], dependencies = [(1, 2), (2, 3)]` Output: `[1, 2, 3]` **Example 2:** Input: `tasks = [1, 2, 3], dependencies = [(1, 2), (2, 1)]` Output: `[]` (There is a cycle)

Suggested Answer

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

No credit card required

More Backend Engineer Interview Prep

Link copied to clipboard