๐ Group Sold Products By The Date
You're working as a data analyst for a bustling marketplace that tracks daily sales. Your task is to create a sales report that shows, for each day, how many unique products were sold and what those products were.
Given an Activities table that records each product sale with its date, you need to:
- ๐ข Count the number of different products sold each day
- ๐ List all product names for each day (sorted alphabetically)
- ๐ Order the results by date
The challenge here is handling duplicate entries - the same product might be sold multiple times on the same day, but we only want to count and list each product once per day.
| Column Name | Type |
|---|---|
| sell_date | date |
| product | varchar |
Note: This table has no primary key and may contain duplicates.
Input & Output
Visualization
Time & Space Complexity
Single pass through data O(n) plus sorting of products within each group O(k log k) where k is products per day
Space for storing intermediate grouped results and sorted products
Constraints
- 1 โค Activities table rows โค 1000
- 1 โค product name length โค 20
- Product names contain only lowercase letters, uppercase letters, and spaces
- sell_date is a valid date in format YYYY-MM-DD
- No primary key - table may contain exact duplicate rows