Skip to content

Commit 9a45339

Browse files
committed
Sync LeetCode submission Runtime - 414 ms (70.52%), Memory - 60.8 MB (100.00%)
1 parent 4e3ed5b commit 9a45339

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<p>Table: <code>Store</code></p>
2+
3+
<pre>
4+
+-------------+------+
5+
| Column Name | Type |
6+
+-------------+------+
7+
| bill_id | int |
8+
| customer_id | int |
9+
| amount | int |
10+
+-------------+------+
11+
bill_id is the primary key (column with unique values) for this table.
12+
Each row contains information about the amount of one bill and the customer associated with it.
13+
</pre>
14+
15+
<p>&nbsp;</p>
16+
17+
<p>Write a solution to report the number of customers who had <strong>at least one</strong> bill with an amount <strong>strictly greater</strong> than <code>500</code>.</p>
18+
19+
<p>The result format is in the following example.</p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong>
26+
Store table:
27+
+---------+-------------+--------+
28+
| bill_id | customer_id | amount |
29+
+---------+-------------+--------+
30+
| 6 | 1 | 549 |
31+
| 8 | 1 | 834 |
32+
| 4 | 2 | 394 |
33+
| 11 | 3 | 657 |
34+
| 13 | 3 | 257 |
35+
+---------+-------------+--------+
36+
<strong>Output:</strong>
37+
+------------+
38+
| rich_count |
39+
+------------+
40+
| 2 |
41+
+------------+
42+
<strong>Explanation:</strong>
43+
Customer 1 has two bills with amounts strictly greater than 500.
44+
Customer 2 does not have any bills with an amount strictly greater than 500.
45+
Customer 3 has one bill with an amount strictly greater than 500.
46+
</pre>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pandas as pd
2+
3+
def count_rich_customers(store: pd.DataFrame) -> pd.DataFrame:
4+
rich_customers = store[store['amount'] > 500]
5+
count = rich_customers['customer_id'].nunique()
6+
return pd.DataFrame({'rich_count': [count]})

0 commit comments

Comments
 (0)