You have five tasks: T1, T2, T3, T4, and T5. If T1 completes, T2 and T3 should be triggered in parallel. If T2 and T3 complete successfully, then T4 and T5 should be triggered in parallel.
💡 Model Answer
The dependency graph can be represented as a directed acyclic graph (DAG). T1 is the root; T2 and T3 depend on T1; T4 and T5 depend on both T2 and T3. A simple solution is to use a thread pool or async framework. First, run T1. When it finishes, submit T2 and T3 to the pool. Use a latch or future join to wait for both to finish. Once both succeed, submit T4 and T5. Error handling: if any task fails, propagate the failure and abort downstream tasks. Complexity: O(n) where n is the number of tasks; parallelism is limited by the number of available workers. This approach scales to larger DAGs and can be implemented with libraries like Java CompletableFuture, Python asyncio, or a workflow engine such as Airflow.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500