The Find the Missing IDs coding problem is a database task. You are given a table Customers with an id column. You are told that the IDs should ideally be a continuous sequence from 1 up to the maximum ID present in the table. Your task is to identify all the IDs in that range that are missing from the table.
Amazon and other large-scale e-commerce companies use this to test your proficiency with SQL interview patterns, specifically Recursive Common Table Expressions (CTEs) or Iterative Row Generation. It evaluation whether you know how to generate a reference sequence of numbers on the fly to perform a "Left Join" or "Difference" operation against the actual data. This is a common requirement for auditing and data integrity checks.
This is a Recursive SQL Query or Number Generation problem.
MAX(id) found in the Customers table.LEFT JOIN between this generated sequence and the Customers table on the ID column.Customers.id is NULL.EXCEPT or NOT IN clause to find the difference between the generated sequence and the existing IDs.Table Customers: [1, 2, 5]
1, 2, 3, 4, 5.Master Recursive CTEs. They are the standard way in modern SQL (PostgreSQL, MySQL 8+, SQL Server) to solve problems that involve hierarchies or generating sequences. If you're using a database that doesn't support them, mention using a system_calendar or a numbers table.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Customer Purchasing Behavior Analysis | Medium | Solve | |
| Employees With Deductions | Medium | Solve | |
| Find Interview Candidates | Medium | Solve | |
| Grand Slam Titles | Medium | Solve | |
| Number of Times a Driver Was a Passenger | Medium | Solve |