Skip to content

Commit 5b5d6a2

Browse files
committed
Sync LeetCode submission Runtime - 541 ms (35.28%), Memory - 61 MB (100.00%)
1 parent 9a45339 commit 5b5d6a2

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<p>Table: <code>Delivery</code></p>
2+
3+
<pre>
4+
+-----------------------------+---------+
5+
| Column Name | Type |
6+
+-----------------------------+---------+
7+
| delivery_id | int |
8+
| customer_id | int |
9+
| order_date | date |
10+
| customer_pref_delivery_date | date |
11+
+-----------------------------+---------+
12+
delivery_id is the primary key (column with unique values) of this table.
13+
The table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).
14+
</pre>
15+
16+
<p>&nbsp;</p>
17+
18+
<p>If the customer&#39;s preferred delivery date is the same as the order date, then the order is called <strong>immediate;</strong> otherwise, it is called <strong>scheduled</strong>.</p>
19+
20+
<p>Write a solution to find the percentage of immediate orders in the table, <strong>rounded to 2 decimal places</strong>.</p>
21+
22+
<p>The result format is in the following example.</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong class="example">Example 1:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong>
29+
Delivery table:
30+
+-------------+-------------+------------+-----------------------------+
31+
| delivery_id | customer_id | order_date | customer_pref_delivery_date |
32+
+-------------+-------------+------------+-----------------------------+
33+
| 1 | 1 | 2019-08-01 | 2019-08-02 |
34+
| 2 | 5 | 2019-08-02 | 2019-08-02 |
35+
| 3 | 1 | 2019-08-11 | 2019-08-11 |
36+
| 4 | 3 | 2019-08-24 | 2019-08-26 |
37+
| 5 | 4 | 2019-08-21 | 2019-08-22 |
38+
| 6 | 2 | 2019-08-11 | 2019-08-13 |
39+
+-------------+-------------+------------+-----------------------------+
40+
<strong>Output:</strong>
41+
+----------------------+
42+
| immediate_percentage |
43+
+----------------------+
44+
| 33.33 |
45+
+----------------------+
46+
<strong>Explanation:</strong> The orders with delivery id 2 and 3 are immediate while the others are scheduled.
47+
</pre>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pandas as pd
2+
3+
def food_delivery(delivery: pd.DataFrame) -> pd.DataFrame:
4+
is_valid = delivery['order_date'] == delivery['customer_pref_delivery_date']
5+
6+
valid_count = is_valid.sum()
7+
total = len(delivery)
8+
9+
percent = round(100 * valid_count / total, 2)
10+
11+
return pd.DataFrame({'immediate_percentage': [percent]})

0 commit comments

Comments
 (0)