Skip to content

Commit 8ca5afc

Browse files
committed
Sync LeetCode submission Runtime - 679 ms (25.29%), Memory - 84.2 MB (99.95%)
1 parent 5b5d6a2 commit 8ca5afc

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<p>Table: <code>Accounts</code></p>
2+
3+
<pre>
4+
+-------------+------+
5+
| Column Name | Type |
6+
+-------------+------+
7+
| account_id | int |
8+
| income | int |
9+
+-------------+------+
10+
account_id is the primary key (column with unique values) for this table.
11+
Each row contains information about the monthly income for one bank account.
12+
</pre>
13+
14+
<p>&nbsp;</p>
15+
16+
<p>Write a solution&nbsp;to calculate the number of bank accounts for each salary category. The salary categories are:</p>
17+
18+
<ul>
19+
<li><code>&quot;Low Salary&quot;</code>: All the salaries <strong>strictly less</strong> than <code>$20000</code>.</li>
20+
<li><code>&quot;Average Salary&quot;</code>: All the salaries in the <strong>inclusive</strong> range <code>[$20000, $50000]</code>.</li>
21+
<li><code>&quot;High Salary&quot;</code>: All the salaries <strong>strictly greater</strong> than <code>$50000</code>.</li>
22+
</ul>
23+
24+
<p>The result table <strong>must</strong> contain all three categories. If there are no accounts in a category,&nbsp;return&nbsp;<code>0</code>.</p>
25+
26+
<p>Return the result table in <strong>any order</strong>.</p>
27+
28+
<p>The&nbsp;result format is in the following example.</p>
29+
30+
<p>&nbsp;</p>
31+
<p><strong class="example">Example 1:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong>
35+
Accounts table:
36+
+------------+--------+
37+
| account_id | income |
38+
+------------+--------+
39+
| 3 | 108939 |
40+
| 2 | 12747 |
41+
| 8 | 87709 |
42+
| 6 | 91796 |
43+
+------------+--------+
44+
<strong>Output:</strong>
45+
+----------------+----------------+
46+
| category | accounts_count |
47+
+----------------+----------------+
48+
| Low Salary | 1 |
49+
| Average Salary | 0 |
50+
| High Salary | 3 |
51+
+----------------+----------------+
52+
<strong>Explanation:</strong>
53+
Low Salary: Account 2.
54+
Average Salary: No accounts.
55+
High Salary: Accounts 3, 6, and 8.
56+
</pre>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pandas as pd
2+
3+
def count_salary_categories(accounts: pd.DataFrame) -> pd.DataFrame:
4+
low_count = (accounts['income'] < 20000).sum()
5+
average_count = ((accounts['income'] >= 20000) & (accounts['income'] <= 50000)).sum()
6+
high_count = (accounts['income'] > 50000).sum()
7+
8+
ans = pd.DataFrame({
9+
'category': ['Low Salary', 'Average Salary', 'High Salary'],
10+
'accounts_count': [low_count, average_count, high_count]
11+
})
12+
13+
return ans

0 commit comments

Comments
 (0)