The Find the Subtasks That Did Not Execute interview question is a data gap analysis task in SQL. You are given two tables: Tasks (listing task IDs and the total number of subtasks each task has) and Executed (listing which specific subtasks for which tasks have actually been completed). Your goal is to generate a report of all subtasks that were not executed for each task.
Google asks the Find the Subtasks That Did Not Execute coding problem to test a candidate's ability to generate "missing" data in a relational database. It evaluations your knowledge of Recursive CTEs (Common Table Expressions) or cross joins to build a comprehensive list of all expected subtasks and then compare it with the actual executed subtasks. This is a vital Database interview pattern for reporting and debugging data pipelines.
This problem follows the Synthetic Sequence Generation pattern.
Tasks table only gives the count of subtasks, you must use a Recursive CTE to generate a row for every subtask index from 1 to subtasks_count for every task.Executed table on both task_id and subtask_id.Executed table has no match (i.e., where Executed.subtask_id IS NULL).Tasks: (id:1, count:3). Executed: (id:1, sub:1), (id:1, sub:3).
(1, 1), (1, 2), (1, 3).(1, 2).Tasks and Executed directly without generating the subtask sequence first.INNER JOIN which would only show subtasks that did execute.Master Recursive CTEs. They are the standard way to expand ranges or build hierarchies in SQL. Understanding how to generate a sequence of numbers on the fly is a common requirement for "Gap Analysis" interview questions.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Median Employee Salary | Hard | Solve | |
| Top Three Wineries | Hard | Solve | |
| Viewers Turned Streamers | Hard | Solve | |
| Trips and Users | Hard | Solve | |
| Department Top Three Salaries | Hard | Solve |