Skip to content

Commit 6cfc90b

Browse files
author
bitoollearner
committed
LeetCode PySpark Solution
1 parent 91e5ae3 commit 6cfc90b

10 files changed

+2039
-70
lines changed

Solved/3050. Pizza Toppings Cost Analysis (Medium)-(Solved).ipynb

Lines changed: 173 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"cell_type": "markdown",
55
"metadata": {
66
"application/vnd.databricks.v1+cell": {
7-
"cellMetadata": {},
7+
"cellMetadata": {
8+
"byteLimit": 2048000,
9+
"rowLimit": 10000
10+
},
811
"inputWidgets": {},
912
"nuid": "4e9d71b1-88e9-445c-820a-b842e217a4e7",
1013
"showTitle": false,
@@ -21,7 +24,10 @@
2124
"execution_count": 0,
2225
"metadata": {
2326
"application/vnd.databricks.v1+cell": {
24-
"cellMetadata": {},
27+
"cellMetadata": {
28+
"byteLimit": 2048000,
29+
"rowLimit": 10000
30+
},
2531
"inputWidgets": {},
2632
"nuid": "e6624c4d-8cb8-4ac4-8c72-81d1b4ecdb57",
2733
"showTitle": false,
@@ -40,7 +46,10 @@
4046
"cell_type": "markdown",
4147
"metadata": {
4248
"application/vnd.databricks.v1+cell": {
43-
"cellMetadata": {},
49+
"cellMetadata": {
50+
"byteLimit": 2048000,
51+
"rowLimit": 10000
52+
},
4453
"inputWidgets": {},
4554
"nuid": "c3788fe5-f4c9-420f-ad72-ec1a39310a2a",
4655
"showTitle": false,
@@ -107,15 +116,27 @@
107116
"execution_count": 0,
108117
"metadata": {
109118
"application/vnd.databricks.v1+cell": {
110-
"cellMetadata": {},
119+
"cellMetadata": {
120+
"byteLimit": 2048000,
121+
"rowLimit": 10000
122+
},
111123
"inputWidgets": {},
112124
"nuid": "137536ea-9bec-4171-8dc2-4bf8b0d771b4",
113125
"showTitle": false,
114126
"tableResultSettingsMap": {},
115127
"title": ""
116128
}
117129
},
118-
"outputs": [],
130+
"outputs": [
131+
{
132+
"output_type": "stream",
133+
"name": "stdout",
134+
"output_type": "stream",
135+
"text": [
136+
"+------------+----+\n|topping_name|cost|\n+------------+----+\n| Pepperoni| 0.5|\n| Sausage| 0.7|\n| Chicken|0.55|\n|Extra Cheese| 0.4|\n+------------+----+\n\n"
137+
]
138+
}
139+
],
119140
"source": [
120141
"toppings_data_3050 = [\n",
121142
" (\"Pepperoni\", 0.50),\n",
@@ -128,15 +149,160 @@
128149
"toppings_df_3050 = spark.createDataFrame(toppings_data_3050, toppings_columns_3050)\n",
129150
"toppings_df_3050.show()"
130151
]
152+
},
153+
{
154+
"cell_type": "code",
155+
"execution_count": 0,
156+
"metadata": {
157+
"application/vnd.databricks.v1+cell": {
158+
"cellMetadata": {
159+
"byteLimit": 2048000,
160+
"rowLimit": 10000
161+
},
162+
"inputWidgets": {},
163+
"nuid": "98fe0f40-1c3c-4706-b434-f3dd26b926f0",
164+
"showTitle": false,
165+
"tableResultSettingsMap": {},
166+
"title": ""
167+
}
168+
},
169+
"outputs": [],
170+
"source": [
171+
"t1_3050 = toppings_df_3050.alias(\"t1_3050\")\n",
172+
"t2_3050 = toppings_df_3050.alias(\"t2_3050\")\n",
173+
"t3_3050 = toppings_df_3050.alias(\"t3_3050\")"
174+
]
175+
},
176+
{
177+
"cell_type": "code",
178+
"execution_count": 0,
179+
"metadata": {
180+
"application/vnd.databricks.v1+cell": {
181+
"cellMetadata": {
182+
"byteLimit": 2048000,
183+
"rowLimit": 10000
184+
},
185+
"inputWidgets": {},
186+
"nuid": "65db7168-b7bc-4698-9e42-76d10e74da32",
187+
"showTitle": false,
188+
"tableResultSettingsMap": {},
189+
"title": ""
190+
}
191+
},
192+
"outputs": [
193+
{
194+
"output_type": "display_data",
195+
"data": {
196+
"text/html": [
197+
"<style scoped>\n",
198+
" .table-result-container {\n",
199+
" max-height: 300px;\n",
200+
" overflow: auto;\n",
201+
" }\n",
202+
" table, th, td {\n",
203+
" border: 1px solid black;\n",
204+
" border-collapse: collapse;\n",
205+
" }\n",
206+
" th, td {\n",
207+
" padding: 5px;\n",
208+
" }\n",
209+
" th {\n",
210+
" text-align: left;\n",
211+
" }\n",
212+
"</style><div class='table-result-container'><table class='table-result'><thead style='background-color: white'><tr><th>pizza</th><th>total_cost</th></tr></thead><tbody><tr><td>Chicken,Pepperoni,Sausage</td><td>1.75</td></tr><tr><td>Chicken,Extra Cheese,Sausage</td><td>1.65</td></tr><tr><td>Extra Cheese,Pepperoni,Sausage</td><td>1.6</td></tr><tr><td>Chicken,Extra Cheese,Pepperoni</td><td>1.45</td></tr></tbody></table></div>"
213+
]
214+
},
215+
"metadata": {
216+
"application/vnd.databricks.v1+output": {
217+
"addedWidgets": {},
218+
"aggData": [],
219+
"aggError": "",
220+
"aggOverflow": false,
221+
"aggSchema": [],
222+
"aggSeriesLimitReached": false,
223+
"aggType": "",
224+
"arguments": {},
225+
"columnCustomDisplayInfos": {},
226+
"data": [
227+
[
228+
"Chicken,Pepperoni,Sausage",
229+
1.75
230+
],
231+
[
232+
"Chicken,Extra Cheese,Sausage",
233+
1.65
234+
],
235+
[
236+
"Extra Cheese,Pepperoni,Sausage",
237+
1.6
238+
],
239+
[
240+
"Chicken,Extra Cheese,Pepperoni",
241+
1.45
242+
]
243+
],
244+
"datasetInfos": [],
245+
"dbfsResultPath": null,
246+
"isJsonSchema": true,
247+
"metadata": {},
248+
"overflow": false,
249+
"plotOptions": {
250+
"customPlotOptions": {},
251+
"displayType": "table",
252+
"pivotAggregation": null,
253+
"pivotColumns": null,
254+
"xColumns": null,
255+
"yColumns": null
256+
},
257+
"removedWidgets": [],
258+
"schema": [
259+
{
260+
"metadata": "{}",
261+
"name": "pizza",
262+
"type": "\"string\""
263+
},
264+
{
265+
"metadata": "{}",
266+
"name": "total_cost",
267+
"type": "\"double\""
268+
}
269+
],
270+
"type": "table"
271+
}
272+
},
273+
"output_type": "display_data"
274+
}
275+
],
276+
"source": [
277+
"t1_3050.join(t2_3050, col(\"t1_3050.topping_name\") < col(\"t2_3050.topping_name\")) \\\n",
278+
" .join(t3_3050, col(\"t2_3050.topping_name\") < col(\"t3_3050.topping_name\")) \\\n",
279+
" .select(\n",
280+
" concat_ws(\",\", \n",
281+
" t1_3050[\"topping_name\"], \n",
282+
" t2_3050[\"topping_name\"], \n",
283+
" t3_3050[\"topping_name\"]\n",
284+
" ).alias(\"pizza\"),\n",
285+
" round(\n",
286+
" t1_3050[\"cost\"] + t2_3050[\"cost\"] + t3_3050[\"cost\"], 2\n",
287+
" ).alias(\"total_cost\")\n",
288+
" ) \\\n",
289+
" .orderBy(col(\"total_cost\").desc(), col(\"pizza\").asc()).display()\n"
290+
]
131291
}
132292
],
133293
"metadata": {
134294
"application/vnd.databricks.v1+notebook": {
135-
"computePreferences": null,
295+
"computePreferences": {
296+
"hardware": {
297+
"accelerator": null,
298+
"gpuPoolId": null,
299+
"memory": null
300+
}
301+
},
136302
"dashboards": [],
137303
"environmentMetadata": {
138304
"base_environment": "",
139-
"environment_version": "1"
305+
"environment_version": "2"
140306
},
141307
"inputWidgetPreferences": null,
142308
"language": "python",

0 commit comments

Comments
 (0)