Find the Team Size — LeetCode 1303 Python Solution
EasyLeetCode PremiumDatabase
- Problem
- #1303
- Reading time
- 3 min
- Source
- leetcode.com
Table schema
SQL
Table: Employee +---------------+---------+ | Column Name | Type | +---------------+---------+ | employee_id | int | | team_id | int | +---------------+---------+ employee_id is the primary key (column with unique values) for this table. Each row of this table contains the ID of each employee and their respective team.Example
SQL
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| employee_id | int |
| team_id | int |
+---------------+---------+
employee_id is the primary key (column with unique values) for this table.
Each row of this table contains the ID of each employee and their respective team.Python solution
Python
import duckdb
import pandas as pd
def solution(employee: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Employee", employee)
return con.execute("""WITH
T AS (
SELECT team_id, COUNT(1) AS team_size
FROM Employee
GROUP BY 1
)
SELECT employee_id, team_size
FROM
Employee
JOIN T USING (team_id);""").df()Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 1303. Find the Team Size?
- LeetCode 1303. Find the Team Size is rated Easy on LeetCode.
- What topics does LeetCode 1303. Find the Team Size cover?
- LeetCode 1303. Find the Team Size is tagged Database on LeetCode.
- Is LeetCode 1303. Find the Team Size a premium problem?
- Yes. LeetCode 1303. Find the Team Size is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.