Implement a TaskList with Prerequisite Dependencies and Cycle Detection
Implement a TaskList interface that manages Task objects, where each Task has a list of sub_tasks (prerequisites that must complete before it can run) and an executable action. The interface supports two methods: addTask(new_task), which adds the task and its subtasks to the list and raises an exception if adding it would create a circular dependency; and pollNext(), which returns the next task whose prerequisites are all complete, returning None once all tasks are finished.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late October, 2026
You have a class Task that holds tasks of type ExecutableThatDrivesResults. Each task contains: - A list of sub_tasks (Task objects), representing prerequisites that must be completed before this task can run. - A result_driving_task (you may assume it behaves like a Runnable). You also have an interface TaskList with two methods: - addTask(new_task): adds new_task and its subtasks to the list. If adding it would create a circular dependency (i.e., a task depends on itself directly or indirectly), raise an exception. Task relationships do not change over time, and tasks are comparable using equality. - pollNext(): returns the next task that can be executed. It should return None once all tasks are complete.
Hello Interview Premium
Your account is free and you can post anonymously if you choose.