You are given a Task class that represents a unit of work and a list of its immediate prerequisites. There are two input lists: one containing every task in the system, and another holding the specific target tasks you care about.
Your job is to implement a method that returns every dependency required by those target tasks, presented in the order they must be completed, and without any duplicates.
all_tasks: a list of all Task objects.target_tasks: a list of the Task objects whose dependencies you need to collect.Task objects representing the complete set of dependencies, in valid execution order, with no repeating entries.Given the full set of tasks:
Task A: Dependencies []
Task B: Dependencies [A]
Task C: Dependencies [B]
Task D: Dependencies [A, C]
Target tasks: [D]
Output: [A, B, C]
Why this output: D directly needs A and C. C in turn needs B, and B needs A. Collecting them in dependency order (A before B before C) gives the required sequence without duplicates.