The Count the Number of Experiments coding problem is a SQL-based challenge. You are given a table Experiments containing columns: platform (Android, iOS, Web), experiment_name (Reading, Sports, Programming), and experiment_id.
The goal is to generate a report that shows the count of experiments for every possible combination of platform and experiment name. If a specific combination has no experiments recorded, you must still include it in the output with a count of 0.
Companies like Strava use this to test proficiency with the database interview pattern involving "outer joins" or "cartesian products." It evaluates whether a candidate knows how to handle missing data. Most basic GROUP BY queries omit rows with zero counts; this problem requires the use of a reference table (usually created via a CROSS JOIN) to ensure all categories are represented.
The SQL pattern used here is Cross Join followed by an Outer Join.
CROSS JOIN between these two lists to get every possible pair.LEFT JOIN from this master pair list to the actual Experiments table.GROUP BY the platform and experiment name and COUNT(experiment_id).Platforms: ['Web', 'Android']
Names: ['Reading', 'Sports']
(Web, Reading), (Web, Sports), (Android, Reading), (Android, Sports).(Web, Reading, ID:1), (Web, Reading, ID:2), (Android, Sports, ID:3).(Web, Reading) -> 2(Web, Sports) -> 0(Android, Reading) -> 0(Android, Sports) -> 1INNER JOIN, which also filters out zero-count rows.COUNT(*) on the left-joined result might return 1 instead of 0 if not careful (since the master row exists). It's safer to count the primary key of the experiments table (COUNT(experiment_id)).Whenever a SQL question says "include all categories, even those with no data," immediately think of a Cross Join to create the full category space, followed by a Left Join. This is a standard template for professional report generation.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Active Businesses | Medium | Solve | |
| Active Users | Medium | Solve | |
| Activity Participants | Medium | Solve | |
| All People Report to the Given Manager | Medium | Solve | |
| All the Pairs With the Maximum Number of Common Followers | Medium | Solve |