Skip to content

Commit 19e5af1

Browse files
author
bitoollearner
committed
LeetCode PySpark Solution
1 parent d040501 commit 19e5af1

11 files changed

+2145
-77
lines changed

Solved/2853. Highest Salaries Difference (Easy)-(Solved).ipynb

Lines changed: 166 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,
@@ -100,15 +109,27 @@
100109
"execution_count": 0,
101110
"metadata": {
102111
"application/vnd.databricks.v1+cell": {
103-
"cellMetadata": {},
112+
"cellMetadata": {
113+
"byteLimit": 2048000,
114+
"rowLimit": 10000
115+
},
104116
"inputWidgets": {},
105117
"nuid": "137536ea-9bec-4171-8dc2-4bf8b0d771b4",
106118
"showTitle": false,
107119
"tableResultSettingsMap": {},
108120
"title": ""
109121
}
110122
},
111-
"outputs": [],
123+
"outputs": [
124+
{
125+
"output_type": "stream",
126+
"name": "stdout",
127+
"output_type": "stream",
128+
"text": [
129+
"+--------+-----------+------+\n|emp_name| department|salary|\n+--------+-----------+------+\n| Kathy|Engineering| 50000|\n| Roy| Marketing| 30000|\n| Charles|Engineering| 45000|\n| Jack|Engineering| 85000|\n|Benjamin| Marketing| 34000|\n| Anthony| Marketing| 42000|\n| Edward|Engineering|102000|\n| Terry|Engineering| 44000|\n| Evelyn| Marketing| 53000|\n| Arthur|Engineering| 32000|\n+--------+-----------+------+\n\n"
130+
]
131+
}
132+
],
112133
"source": [
113134
"salaries_data_2853 = [\n",
114135
" (\"Kathy\", \"Engineering\", 50000),\n",
@@ -127,15 +148,153 @@
127148
"salaries_df_2853 = spark.createDataFrame(salaries_data_2853, salaries_columns_2853)\n",
128149
"salaries_df_2853.show()"
129150
]
151+
},
152+
{
153+
"cell_type": "code",
154+
"execution_count": 0,
155+
"metadata": {
156+
"application/vnd.databricks.v1+cell": {
157+
"cellMetadata": {
158+
"byteLimit": 2048000,
159+
"rowLimit": 10000
160+
},
161+
"inputWidgets": {},
162+
"nuid": "4f5479e7-5d1f-455a-875e-5040c6bcee1c",
163+
"showTitle": false,
164+
"tableResultSettingsMap": {},
165+
"title": ""
166+
}
167+
},
168+
"outputs": [],
169+
"source": [
170+
"dept_max_2853 = salaries_df_2853\\\n",
171+
" .groupBy(\"department\")\\\n",
172+
" .agg(max(\"salary\").alias(\"max_salary\"))"
173+
]
174+
},
175+
{
176+
"cell_type": "code",
177+
"execution_count": 0,
178+
"metadata": {
179+
"application/vnd.databricks.v1+cell": {
180+
"cellMetadata": {
181+
"byteLimit": 2048000,
182+
"rowLimit": 10000
183+
},
184+
"inputWidgets": {},
185+
"nuid": "02214221-d627-4ec2-9985-0a9e3fd8e750",
186+
"showTitle": false,
187+
"tableResultSettingsMap": {},
188+
"title": ""
189+
}
190+
},
191+
"outputs": [],
192+
"source": [
193+
"pivoted_2853 = dept_max_2853\\\n",
194+
" .groupBy().pivot(\"department\").agg(first(\"max_salary\"))"
195+
]
196+
},
197+
{
198+
"cell_type": "code",
199+
"execution_count": 0,
200+
"metadata": {
201+
"application/vnd.databricks.v1+cell": {
202+
"cellMetadata": {
203+
"byteLimit": 2048000,
204+
"rowLimit": 10000
205+
},
206+
"inputWidgets": {},
207+
"nuid": "2ae57ec4-0458-4729-a555-0f717ca2a684",
208+
"showTitle": false,
209+
"tableResultSettingsMap": {},
210+
"title": ""
211+
}
212+
},
213+
"outputs": [
214+
{
215+
"output_type": "display_data",
216+
"data": {
217+
"text/html": [
218+
"<style scoped>\n",
219+
" .table-result-container {\n",
220+
" max-height: 300px;\n",
221+
" overflow: auto;\n",
222+
" }\n",
223+
" table, th, td {\n",
224+
" border: 1px solid black;\n",
225+
" border-collapse: collapse;\n",
226+
" }\n",
227+
" th, td {\n",
228+
" padding: 5px;\n",
229+
" }\n",
230+
" th {\n",
231+
" text-align: left;\n",
232+
" }\n",
233+
"</style><div class='table-result-container'><table class='table-result'><thead style='background-color: white'><tr><th>salary_difference</th></tr></thead><tbody><tr><td>49000</td></tr></tbody></table></div>"
234+
]
235+
},
236+
"metadata": {
237+
"application/vnd.databricks.v1+output": {
238+
"addedWidgets": {},
239+
"aggData": [],
240+
"aggError": "",
241+
"aggOverflow": false,
242+
"aggSchema": [],
243+
"aggSeriesLimitReached": false,
244+
"aggType": "",
245+
"arguments": {},
246+
"columnCustomDisplayInfos": {},
247+
"data": [
248+
[
249+
49000
250+
]
251+
],
252+
"datasetInfos": [],
253+
"dbfsResultPath": null,
254+
"isJsonSchema": true,
255+
"metadata": {},
256+
"overflow": false,
257+
"plotOptions": {
258+
"customPlotOptions": {},
259+
"displayType": "table",
260+
"pivotAggregation": null,
261+
"pivotColumns": null,
262+
"xColumns": null,
263+
"yColumns": null
264+
},
265+
"removedWidgets": [],
266+
"schema": [
267+
{
268+
"metadata": "{}",
269+
"name": "salary_difference",
270+
"type": "\"long\""
271+
}
272+
],
273+
"type": "table"
274+
}
275+
},
276+
"output_type": "display_data"
277+
}
278+
],
279+
"source": [
280+
"pivoted_2853\\\n",
281+
" .select( abs(col(\"Engineering\") - col(\"Marketing\")).alias(\"salary_difference\")).display()"
282+
]
130283
}
131284
],
132285
"metadata": {
133286
"application/vnd.databricks.v1+notebook": {
134-
"computePreferences": null,
287+
"computePreferences": {
288+
"hardware": {
289+
"accelerator": null,
290+
"gpuPoolId": null,
291+
"memory": null
292+
}
293+
},
135294
"dashboards": [],
136295
"environmentMetadata": {
137296
"base_environment": "",
138-
"environment_version": "1"
297+
"environment_version": "2"
139298
},
140299
"inputWidgetPreferences": null,
141300
"language": "python",

0 commit comments

Comments
 (0)