EasyNo. 0584
Find Customer Referee — LeetCode 584 Python Solution
- Topics
- Database
- Reading time
- 2 min
- Source
- leetcode.com
The problem
List the names of the customers who were not referred by the customer with id 2, which includes everyone who was not referred by anybody. The Customer table has id (int, primary key), name (varchar) and referee_id (int), the id of the customer who referred them, or null when nobody did. Return the names in a column called name.
Example
- Input
- Customer(id, name, referee_id) = (1, 'Ana', null), (2, 'Ben', null), (3, 'Cleo', 2), (4, 'Dev', 1), (5, 'Eve', 2)
- Output
- name = 'Ana', 'Ben', 'Dev'
- Explanation
- Only Cleo and Eve carry referee_id 2; the rows with a null referee_id are kept because "not referred by 2" includes "not referred at all".
Python solution
import pandas as pd
def find_customer_referee(customer: pd.DataFrame) -> pd.DataFrame:
res = customer[(customer['referee_id'].isna()) | (customer['referee_id'] != 2)]
return res[['name']]Complexity
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0585 | Investments in 2016 | Medium |
| 0586 | Customer Placing the Largest Number of Orders | Easy |
| 0577 | Employee Bonus | Easy |
| 0175 | Combine Two Tables | Easy |
| 0176 | Second Highest Salary | Medium |
| 0177 | Nth Highest Salary | Medium |
Frequently asked questions
- How hard is LeetCode 584. Find Customer Referee?
LeetCode 584. Find Customer Referee is rated Easy on LeetCode.
- What topics does LeetCode 584. Find Customer Referee cover?
LeetCode 584. Find Customer Referee is tagged Database on LeetCode.