Skip to content

Commit 9da42c7

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

5 files changed

+1024
-36
lines changed

Solved/2990. Loan Types (Easy)-(Solved).ipynb

Lines changed: 149 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,
@@ -103,15 +112,27 @@
103112
"execution_count": 0,
104113
"metadata": {
105114
"application/vnd.databricks.v1+cell": {
106-
"cellMetadata": {},
115+
"cellMetadata": {
116+
"byteLimit": 2048000,
117+
"rowLimit": 10000
118+
},
107119
"inputWidgets": {},
108120
"nuid": "137536ea-9bec-4171-8dc2-4bf8b0d771b4",
109121
"showTitle": false,
110122
"tableResultSettingsMap": {},
111123
"title": ""
112124
}
113125
},
114-
"outputs": [],
126+
"outputs": [
127+
{
128+
"output_type": "stream",
129+
"name": "stdout",
130+
"output_type": "stream",
131+
"text": [
132+
"+-------+-------+---------+\n|loan_id|user_id|loan_type|\n+-------+-------+---------+\n| 683| 101| Mortgage|\n| 218| 101| AutoLoan|\n| 802| 101| Inschool|\n| 593| 102| Mortgage|\n| 138| 102|Refinance|\n| 294| 102| Inschool|\n| 308| 103|Refinance|\n| 389| 104| Mortgage|\n+-------+-------+---------+\n\n"
133+
]
134+
}
135+
],
115136
"source": [
116137
"loans_data_2990 = [\n",
117138
" (683, 101, \"Mortgage\"),\n",
@@ -128,15 +149,136 @@
128149
"loans_df_2990 = spark.createDataFrame(loans_data_2990, loans_columns_2990)\n",
129150
"loans_df_2990.show()\n"
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": "97a827c1-3c2e-47de-8b50-6454b8ab3939",
164+
"showTitle": false,
165+
"tableResultSettingsMap": {},
166+
"title": ""
167+
}
168+
},
169+
"outputs": [],
170+
"source": [
171+
"loan_counts_2990 = loans_df_2990\\\n",
172+
" .groupBy(\"user_id\")\\\n",
173+
" .agg(\n",
174+
" collect_set(\"loan_type\").alias(\"loan_types\")\n",
175+
" )"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": 0,
181+
"metadata": {
182+
"application/vnd.databricks.v1+cell": {
183+
"cellMetadata": {
184+
"byteLimit": 2048000,
185+
"rowLimit": 10000
186+
},
187+
"inputWidgets": {},
188+
"nuid": "e4e672d5-8f63-488a-9344-3c8cfca7ed63",
189+
"showTitle": false,
190+
"tableResultSettingsMap": {},
191+
"title": ""
192+
}
193+
},
194+
"outputs": [
195+
{
196+
"output_type": "display_data",
197+
"data": {
198+
"text/html": [
199+
"<style scoped>\n",
200+
" .table-result-container {\n",
201+
" max-height: 300px;\n",
202+
" overflow: auto;\n",
203+
" }\n",
204+
" table, th, td {\n",
205+
" border: 1px solid black;\n",
206+
" border-collapse: collapse;\n",
207+
" }\n",
208+
" th, td {\n",
209+
" padding: 5px;\n",
210+
" }\n",
211+
" th {\n",
212+
" text-align: left;\n",
213+
" }\n",
214+
"</style><div class='table-result-container'><table class='table-result'><thead style='background-color: white'><tr><th>user_id</th></tr></thead><tbody><tr><td>102</td></tr></tbody></table></div>"
215+
]
216+
},
217+
"metadata": {
218+
"application/vnd.databricks.v1+output": {
219+
"addedWidgets": {},
220+
"aggData": [],
221+
"aggError": "",
222+
"aggOverflow": false,
223+
"aggSchema": [],
224+
"aggSeriesLimitReached": false,
225+
"aggType": "",
226+
"arguments": {},
227+
"columnCustomDisplayInfos": {},
228+
"data": [
229+
[
230+
102
231+
]
232+
],
233+
"datasetInfos": [],
234+
"dbfsResultPath": null,
235+
"isJsonSchema": true,
236+
"metadata": {},
237+
"overflow": false,
238+
"plotOptions": {
239+
"customPlotOptions": {},
240+
"displayType": "table",
241+
"pivotAggregation": null,
242+
"pivotColumns": null,
243+
"xColumns": null,
244+
"yColumns": null
245+
},
246+
"removedWidgets": [],
247+
"schema": [
248+
{
249+
"metadata": "{}",
250+
"name": "user_id",
251+
"type": "\"long\""
252+
}
253+
],
254+
"type": "table"
255+
}
256+
},
257+
"output_type": "display_data"
258+
}
259+
],
260+
"source": [
261+
"loan_counts_2990\\\n",
262+
" .filter(\n",
263+
" (array_contains(col(\"loan_types\"), \"Refinance\")) &\n",
264+
" (array_contains(col(\"loan_types\"), \"Mortgage\")))\\\n",
265+
" .select(\"user_id\").orderBy(\"user_id\").display()"
266+
]
131267
}
132268
],
133269
"metadata": {
134270
"application/vnd.databricks.v1+notebook": {
135-
"computePreferences": null,
271+
"computePreferences": {
272+
"hardware": {
273+
"accelerator": null,
274+
"gpuPoolId": null,
275+
"memory": null
276+
}
277+
},
136278
"dashboards": [],
137279
"environmentMetadata": {
138280
"base_environment": "",
139-
"environment_version": "1"
281+
"environment_version": "2"
140282
},
141283
"inputWidgetPreferences": null,
142284
"language": "python",

0 commit comments

Comments
 (0)