Daily Leads and Partners — LeetCode 1693 Python Solution
EasyDatabase
- Problem
- #1693
- Reading time
- 3 min
- Source
- leetcode.com
Table schema
SQL
Table: DailySales +-------------+---------+ | Column Name | Type | +-------------+---------+ | date_id | date | | make_name | varchar | | lead_id | int | | partner_id | int | +-------------+---------+ There is no primary key (column with unique values) for this table. It may contain duplicates.Example
SQL
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| date_id | date |
| make_name | varchar |
| lead_id | int |
| partner_id | int |
+-------------+---------+
There is no primary key (column with unique values) for this table. It may contain duplicates.
This table contains the date and the name of the product sold and the IDs of the lead and partner it was sold to.
The name consists of only lowercase English letters.Python solution
Python
import duckdb
import pandas as pd
def solution(daily_sales: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("DailySales", daily_sales)
return con.execute("""SELECT
date_id,
make_name,
COUNT(DISTINCT lead_id) AS unique_leads,
COUNT(DISTINCT partner_id) AS unique_partners
FROM DailySales
GROUP BY 1, 2;""").df()Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 1693. Daily Leads and Partners?
- LeetCode 1693. Daily Leads and Partners is rated Easy on LeetCode.
- What topics does LeetCode 1693. Daily Leads and Partners cover?
- LeetCode 1693. Daily Leads and Partners is tagged Database on LeetCode.