Loading problem...
A retail intelligence team is building a "buy together" recommendation widget for product detail pages.
Table: ProductPurchases
Table: ProductInfo
Task: Find product pairs that are commonly purchased by the same customers.
Rules:
Output requirements:
Supported submission environments:
ProductPurchases:
| user_id | product_id | quantity |
|---------|------------|----------|
| 1 | 101 | 2 |
| 1 | 102 | 1 |
| 1 | 103 | 1 |
| 2 | 101 | 1 |
| 2 | 102 | 4 |
| 2 | 104 | 1 |
| 3 | 101 | 1 |
| 3 | 102 | 2 |
| 3 | 103 | 2 |
| 4 | 101 | 1 |
| 4 | 103 | 3 |
| 4 | 104 | 1 |
| 5 | 102 | 2 |
| 5 | 104 | 1 |
ProductInfo:
| product_id | category | price |
|------------|--------------|-------|
| 101 | Electronics | 120 |
| 102 | Books | 25 |
| 103 | Fitness | 70 |
| 104 | Home | 45 |[
{"product1_id":101,"product2_id":102,"product1_category":"Electronics","product2_category":"Books","customer_count":3},
{"product1_id":101,"product2_id":103,"product1_category":"Electronics","product2_category":"Fitness","customer_count":3}
]Pair (101,102) appears for users 1, 2, and 3. Pair (101,103) appears for users 1, 3, and 4. Other pairs do not reach the minimum threshold of 3 distinct users.
ProductPurchases:
| user_id | product_id | quantity |
|---------|------------|----------|
| 10 | 201 | 1 |
| 10 | 202 | 1 |
| 11 | 201 | 2 |
| 11 | 202 | 1 |
| 11 | 203 | 2 |
| 12 | 201 | 1 |
| 12 | 203 | 1 |
| 13 | 202 | 1 |
| 13 | 203 | 3 |
| 14 | 201 | 1 |
| 14 | 202 | 1 |
| 14 | 203 | 1 |
ProductInfo:
| product_id | category | price |
|------------|--------------|-------|
| 201 | Kitchen | 40 |
| 202 | Garden | 55 |
| 203 | Storage | 30 |[
{"product1_id":201,"product2_id":202,"product1_category":"Kitchen","product2_category":"Garden","customer_count":3},
{"product1_id":201,"product2_id":203,"product1_category":"Kitchen","product2_category":"Storage","customer_count":3},
{"product1_id":202,"product2_id":203,"product1_category":"Garden","product2_category":"Storage","customer_count":3}
]All three pairs have equal customer_count = 3, so tie-breaking falls back to product1_id and then product2_id ascending.
ProductPurchases:
| user_id | product_id | quantity |
|---------|------------|----------|
| 21 | 301 | 1 |
| 21 | 302 | 1 |
| 22 | 301 | 1 |
| 22 | 303 | 1 |
| 23 | 302 | 1 |
| 23 | 303 | 1 |
ProductInfo:
| product_id | category | price |
|------------|--------------|-------|
| 301 | Office | 15 |
| 302 | Stationery | 5 |
| 303 | Accessories | 12 |[]Every pair is shared by fewer than 3 users, so no recommendation pair qualifies for output.
Constraints