Skip tasks that already ran

Python data engineering interview problem. Difficulty: beginner. Pattern: Arrays. About 10 minutes. Free to practice.

After a failed run, work out which tasks still need to run so a re-run does not repeat finished work. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

A nightly pipeline failed halfway. When it is run again, it must not repeat the tasks that already finished. Implement tasks_to_run(planned, completed). planned is the list of task names in the order they should run. completed is the list of task names that already finished. Return the planned tasks that are not completed, in planned order. If a task name appears twice in planned, run it only once, at its first position.

Requirements

  • Keep the planned order.
  • Each task appears at most once in the result.

Constraints

  • Task names are strings.
  • The input lists are not changed.

Examples

Input: tasks_to_run(['a', 'b', 'a', 'c'], ['b']) Output: ['a', 'c'] The repeated a is kept once and the finished b is skipped.

Topics: lakebench, python, idempotent, rerun, pipeline.

More Python interview questions · All interview problems · Learn data engineering

beginner

Skip tasks that already ran

Interview-style drill: After a failed run, work out which tasks still need to run so a re-run does not repeat finished work.

A nightly pipeline failed halfway. When it is run again, it must not repeat the tasks that already finished. Implement `tasks_to_run(planned, completed)`. - `planned` is the list of task names in the order they should run. - `completed` is the list of task names that already finished. - Return the planned tasks that are not completed, in planned order. - If a task name appears twice in `planned`, run it only once, at its first position.