Find Observed Customers Who Purchased the Entire Product Set

Quick Overview

Find customers who purchased every product, counting repeated purchases of the same product only once.

Find Observed Customers Who Purchased the Entire Product Set

Company: Meta

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

### Problem Return customer_id values appearing in Customer that bought every product_key in Product. Repeated Customer rows do not represent additional distinct products. Return each qualifying customer once, in any order. A NULL product key records no purchase. If Product is empty, every observed customer qualifies. ### Tables Table: `Customer` ```text +-------------+---------+ | Column Name | Type | +-------------+---------+ | customer_id | int | | product_key | int | +-------------+---------+ This table may contain duplicates rows. customer_id is not NULL. product_key is a foreign key (reference column) to Product table. ``` Table: `Product` ```text +-------------+---------+ | Column Name | Type | +-------------+---------+ | product_key | int | +-------------+---------+ product_key is the primary key (column with unique values) for this table. ``` ### Example ```text Product (product_key): (8), (9) Customer (customer_id,product_key): (1,8), (1,8), (1,9), (2,8), (3,9) Output (customer_id): (1) ``` ### What a Strong Answer Covers - Compare each observed customer's distinct purchases with the full product set. - Return each qualifying customer once and handle repeated purchases and an empty product list. ### Follow-up Questions - How would you report the products each customer is missing? - How would you require only products in a particular category?

Overview: Find customers who purchased every product, counting repeated purchases of the same product only once.

Meta logo
Meta
mediumSoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Return customer_id values appearing in Customer that bought every product_key in Product. Repeated Customer rows do not represent additional distinct products. Return each qualifying customer once, in any order. A NULL product key records no purchase. If Product is empty, every observed customer qualifies.

Tables

Table: Customer

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| customer_id | int     |
| product_key | int     |
+-------------+---------+
This table may contain duplicates rows.
customer_id is not NULL.
product_key is a foreign key (reference column) to Product table.

Table: Product

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| product_key | int     |
+-------------+---------+
product_key is the primary key (column with unique values) for this table.

Example

Product (product_key): (8), (9)
Customer (customer_id,product_key): (1,8), (1,8), (1,9), (2,8), (3,9)
Output (customer_id): (1)

What a Strong Answer Covers Guidance

  • Compare each observed customer's distinct purchases with the full product set.
  • Return each qualifying customer once and handle repeated purchases and an empty product list.

Follow-up Questions Guidance

  • How would you report the products each customer is missing?
  • How would you require only products in a particular category?