Tasks that are ready to run
Python data engineering interview problem. Difficulty: beginner. Pattern: Dictionaries. About 10 minutes. Free to practice.
Given each task's dependencies and the tasks that finished, list the tasks a scheduler may start now. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
A scheduler starts a task only when everything it depends on has finished. Implement ready_tasks(dependencies, done). dependencies is a dict. Each key is a task name and its value is the list of tasks it depends on (possibly empty). done is the list of tasks that have finished. Return the tasks that are ready to start: not finished yet, and every dependency finished. Return the names sorted alphabetically.
Requirements
- Finished tasks are never returned.
- The result is sorted alphabetically.
Constraints
- Every dependency is also a key in dependencies.
- The inputs are not changed.
Examples
Input: ready_tasks({'a': [], 'b': ['a'], 'c': ['a', 'b']}, ['a']) Output: ['b'] b is ready once a is done. c still waits for b.
Topics: lakebench, python, dependency, scheduler, pipeline.
More Python interview questions · All interview problems · Learn data engineering
Tasks that are ready to run
Interview-style drill: Given each task's dependencies and the tasks that finished, list the tasks a scheduler may start now.
A scheduler starts a task only when everything it depends on has finished. Implement `ready_tasks(dependencies, done)`. - `dependencies` is a dict. Each key is a task name and its value is the list of tasks it depends on (possibly empty). - `done` is the list of tasks that have finished. - Return the tasks that are ready to start: not finished yet, and every dependency finished. - Return the names sorted alphabetically.