Skip to content

Commit c260745

Browse files
author
bitoollearner
committed
LeetCode Question Solution
LeetCode Question Solution
1 parent f0394fb commit c260745

11 files changed

+830
-81
lines changed

Solved/1112. Highest Grade For Each Student (Medium)-(Solved).ipynb

Lines changed: 73 additions & 8 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": "3f2ab884-5b2e-4c2a-b90f-eba6d7208edf",
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": "26c9d69f-b471-43b4-aaee-40c41d01994e",
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": "fa1c2280-e46c-403e-8996-25b01a84ec72",
4655
"showTitle": false,
@@ -97,7 +106,10 @@
97106
"execution_count": 0,
98107
"metadata": {
99108
"application/vnd.databricks.v1+cell": {
100-
"cellMetadata": {},
109+
"cellMetadata": {
110+
"byteLimit": 2048000,
111+
"rowLimit": 10000
112+
},
101113
"inputWidgets": {},
102114
"nuid": "dddf2382-d3f5-49ba-9108-34f298edfb81",
103115
"showTitle": false,
@@ -121,25 +133,78 @@
121133
"enrollments_df_1112 = spark.createDataFrame(enrollments_data_1112, enrollments_columns_1112)\n",
122134
"enrollments_df_1112.show()"
123135
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": 0,
140+
"metadata": {
141+
"application/vnd.databricks.v1+cell": {
142+
"cellMetadata": {
143+
"byteLimit": 2048000,
144+
"rowLimit": 10000
145+
},
146+
"inputWidgets": {},
147+
"nuid": "c5e0352f-718b-4b19-9cb3-37ce75a148de",
148+
"showTitle": false,
149+
"tableResultSettingsMap": {},
150+
"title": ""
151+
}
152+
},
153+
"outputs": [],
154+
"source": [
155+
"window_spec = Window.partitionBy(\"student_id\").orderBy(col(\"grade\").desc(), col(\"course_id\").asc())"
156+
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"execution_count": 0,
161+
"metadata": {
162+
"application/vnd.databricks.v1+cell": {
163+
"cellMetadata": {
164+
"byteLimit": 2048000,
165+
"rowLimit": 10000
166+
},
167+
"inputWidgets": {},
168+
"nuid": "6c0d1b87-4dbb-4450-b931-46262578f5a3",
169+
"showTitle": false,
170+
"tableResultSettingsMap": {},
171+
"title": ""
172+
}
173+
},
174+
"outputs": [],
175+
"source": [
176+
"enrollments_df_1112\\\n",
177+
" .withColumn(\"rn\", row_number().over(window_spec))\\\n",
178+
" .filter(col(\"rn\") == 1).select(\"student_id\", \"course_id\", \"grade\").orderBy(\"student_id\").show()\n"
179+
]
124180
}
125181
],
126182
"metadata": {
127183
"application/vnd.databricks.v1+notebook": {
128-
"computePreferences": null,
184+
"computePreferences": {
185+
"hardware": {
186+
"accelerator": null,
187+
"gpuPoolId": null,
188+
"memory": null
189+
}
190+
},
129191
"dashboards": [],
130192
"environmentMetadata": {
131193
"base_environment": "",
132-
"environment_version": "1"
194+
"environment_version": "2"
133195
},
134196
"inputWidgetPreferences": null,
135197
"language": "python",
136198
"notebookMetadata": {
137199
"pythonIndentUnit": 4
138200
},
139-
"notebookName": "1112. Highest Grade For Each Student (Medium)",
201+
"notebookName": "1112. Highest Grade For Each Student (Medium)-(Solved)",
140202
"widgets": {}
203+
},
204+
"language_info": {
205+
"name": "python"
141206
}
142207
},
143208
"nbformat": 4,
144209
"nbformat_minor": 0
145-
}
210+
}

Solved/1113. Reported Posts (Easy)-(Solved).ipynb

Lines changed: 55 additions & 8 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": "3f2ab884-5b2e-4c2a-b90f-eba6d7208edf",
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": "26c9d69f-b471-43b4-aaee-40c41d01994e",
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": "fa1c2280-e46c-403e-8996-25b01a84ec72",
4655
"showTitle": false,
@@ -108,7 +117,10 @@
108117
"execution_count": 0,
109118
"metadata": {
110119
"application/vnd.databricks.v1+cell": {
111-
"cellMetadata": {},
120+
"cellMetadata": {
121+
"byteLimit": 2048000,
122+
"rowLimit": 10000
123+
},
112124
"inputWidgets": {},
113125
"nuid": "dddf2382-d3f5-49ba-9108-34f298edfb81",
114126
"showTitle": false,
@@ -138,25 +150,60 @@
138150
"actions_df_1113 = spark.createDataFrame(actions_data_1113, actions_columns_1113)\n",
139151
"actions_df_1113.show()"
140152
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": 0,
157+
"metadata": {
158+
"application/vnd.databricks.v1+cell": {
159+
"cellMetadata": {
160+
"byteLimit": 2048000,
161+
"rowLimit": 10000
162+
},
163+
"inputWidgets": {},
164+
"nuid": "522c3e29-6c1b-456c-b4f8-a72d4ec94acf",
165+
"showTitle": false,
166+
"tableResultSettingsMap": {},
167+
"title": ""
168+
}
169+
},
170+
"outputs": [],
171+
"source": [
172+
"actions_df_1113\\\n",
173+
" .filter(\n",
174+
" (col(\"action\") == \"report\") & \n",
175+
" (col(\"action_date\") == \"2019-07-04\"))\\\n",
176+
" .groupBy(\"extra\").agg(countDistinct(\"post_id\").alias(\"report_count\")) \\\n",
177+
" .withColumnRenamed(\"extra\", \"report_reason\").show()"
178+
]
141179
}
142180
],
143181
"metadata": {
144182
"application/vnd.databricks.v1+notebook": {
145-
"computePreferences": null,
183+
"computePreferences": {
184+
"hardware": {
185+
"accelerator": null,
186+
"gpuPoolId": null,
187+
"memory": null
188+
}
189+
},
146190
"dashboards": [],
147191
"environmentMetadata": {
148192
"base_environment": "",
149-
"environment_version": "1"
193+
"environment_version": "2"
150194
},
151195
"inputWidgetPreferences": null,
152196
"language": "python",
153197
"notebookMetadata": {
154198
"pythonIndentUnit": 4
155199
},
156-
"notebookName": "1113. Reported Posts (Easy)",
200+
"notebookName": "1113. Reported Posts (Easy)-(Solved)",
157201
"widgets": {}
202+
},
203+
"language_info": {
204+
"name": "python"
158205
}
159206
},
160207
"nbformat": 4,
161208
"nbformat_minor": 0
162-
}
209+
}

0 commit comments

Comments
 (0)