Skip to content

Commit c77028c

Browse files
author
bitoollearner
committed
Leet Code Question Solution Batch-1
Leet Code Question Solution Batch-1
1 parent 3a136eb commit c77028c

10 files changed

+621
-77
lines changed

Solved/175. Combine Two Tables (Easy)-(Solved).ipynb

Lines changed: 66 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": "6ceade8c-5d68-44c3-b924-99dcd1835de1",
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": "b0ae7759-c286-4d5f-a99a-8bd44092482d",
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": "a0369f69-7f69-4975-b78a-ff2692e60dfd",
4655
"showTitle": false,
@@ -111,7 +120,10 @@
111120
"execution_count": 0,
112121
"metadata": {
113122
"application/vnd.databricks.v1+cell": {
114-
"cellMetadata": {},
123+
"cellMetadata": {
124+
"byteLimit": 2048000,
125+
"rowLimit": 10000
126+
},
115127
"inputWidgets": {},
116128
"nuid": "071ffb6e-6e78-4482-8caf-e9a180fa3776",
117129
"showTitle": false,
@@ -139,22 +151,69 @@
139151
"address_df_175 = spark.createDataFrame(address_175, address_columns_175)\n",
140152
"address_df_175.show()\n"
141153
]
154+
},
155+
{
156+
"cell_type": "code",
157+
"execution_count": 0,
158+
"metadata": {
159+
"application/vnd.databricks.v1+cell": {
160+
"cellMetadata": {
161+
"byteLimit": 2048000,
162+
"rowLimit": 10000
163+
},
164+
"inputWidgets": {},
165+
"nuid": "b23dcad0-065b-4be9-be9f-079834d74a03",
166+
"showTitle": false,
167+
"tableResultSettingsMap": {},
168+
"title": ""
169+
}
170+
},
171+
"outputs": [],
172+
"source": [
173+
"Person_175 = [\n",
174+
" (1, \"Wang\", \"Allen\"),\n",
175+
" (2, \"Alice\", \"Bob\")\n",
176+
"]\n",
177+
"\n",
178+
"Person_columns_175 = [\"personId\", \"lastName\", \"firstName\"]\n",
179+
"Person_df_175 = spark.createDataFrame(Person_175, Person_columns_175)\n",
180+
"Person_df_175.show()\n",
181+
"\n",
182+
"address_175 = [\n",
183+
" (1, 2, \"New York City\", \"New York\"),\n",
184+
" (2, 3, \"Leetcode\", \"California\")\n",
185+
"]\n",
186+
"\n",
187+
"address_columns_175 = [\"addressId\", \"personId\", \"city\", \"state\"]\n",
188+
"address_df_175 = spark.createDataFrame(address_175, address_columns_175)\n",
189+
"address_df_175.show()\n"
190+
]
142191
}
143192
],
144193
"metadata": {
145194
"application/vnd.databricks.v1+notebook": {
146-
"computePreferences": null,
195+
"computePreferences": {
196+
"hardware": {
197+
"accelerator": null,
198+
"gpuPoolId": null,
199+
"memory": null
200+
}
201+
},
147202
"dashboards": [],
148203
"environmentMetadata": {
149204
"base_environment": "",
150-
"client": "1"
205+
"environment_version": "2"
151206
},
207+
"inputWidgetPreferences": null,
152208
"language": "python",
153209
"notebookMetadata": {
154210
"pythonIndentUnit": 4
155211
},
156-
"notebookName": "175. Combine Two Tables (Easy)",
212+
"notebookName": "175. Combine Two Tables (Easy)-(Solved)",
157213
"widgets": {}
214+
},
215+
"language_info": {
216+
"name": "python"
158217
}
159218
},
160219
"nbformat": 4,

Solved/176. Second Highest Salary (Medium)-(Solved).ipynb

Lines changed: 52 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": "751b4999-4972-4df9-849c-62cb74280e43",
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": "e27d38fe-6e1e-4e06-a0ba-3bc38abe2dfd",
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": "a65c660f-6220-469e-9a9d-7be67fc1c1d7",
4655
"showTitle": false,
@@ -100,7 +109,10 @@
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": "a67baad4-69ab-4342-af4c-a92d0485c68b",
106118
"showTitle": false,
@@ -116,22 +128,55 @@
116128
"employee_df_176 = spark.createDataFrame(employee_176, employee_columns_176)\n",
117129
"employee_df_176.show()"
118130
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": 0,
135+
"metadata": {
136+
"application/vnd.databricks.v1+cell": {
137+
"cellMetadata": {
138+
"byteLimit": 2048000,
139+
"rowLimit": 10000
140+
},
141+
"inputWidgets": {},
142+
"nuid": "50c1bfbb-33e7-4fb3-9741-2c4b3d334119",
143+
"showTitle": false,
144+
"tableResultSettingsMap": {},
145+
"title": ""
146+
}
147+
},
148+
"outputs": [],
149+
"source": [
150+
"employee_df_176\\\n",
151+
" .select(\"id\",col(\"salary\").cast('int')).orderBy(col('salary').desc()).limit(2)\\\n",
152+
" .orderBy(col('salary').asc()).limit(1).show()"
153+
]
119154
}
120155
],
121156
"metadata": {
122157
"application/vnd.databricks.v1+notebook": {
123-
"computePreferences": null,
158+
"computePreferences": {
159+
"hardware": {
160+
"accelerator": null,
161+
"gpuPoolId": null,
162+
"memory": null
163+
}
164+
},
124165
"dashboards": [],
125166
"environmentMetadata": {
126167
"base_environment": "",
127-
"client": "1"
168+
"environment_version": "2"
128169
},
170+
"inputWidgetPreferences": null,
129171
"language": "python",
130172
"notebookMetadata": {
131173
"pythonIndentUnit": 4
132174
},
133-
"notebookName": "176. Second Highest Salary (Medium)",
175+
"notebookName": "176. Second Highest Salary (Medium)-(Solved)",
134176
"widgets": {}
177+
},
178+
"language_info": {
179+
"name": "python"
135180
}
136181
},
137182
"nbformat": 4,

Solved/177. Nth Highest Salary (Medium)-(Solved).ipynb

Lines changed: 51 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": "6555a7e2-9a4c-4919-8959-bf6edcc5ca0e",
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": "278d9de7-2e50-4a96-b4d4-c8847f1e58c1",
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": "3734811c-0c8d-4fb4-a170-4e53f123f29a",
4655
"showTitle": false,
@@ -101,7 +110,10 @@
101110
"execution_count": 0,
102111
"metadata": {
103112
"application/vnd.databricks.v1+cell": {
104-
"cellMetadata": {},
113+
"cellMetadata": {
114+
"byteLimit": 2048000,
115+
"rowLimit": 10000
116+
},
105117
"inputWidgets": {},
106118
"nuid": "707dd883-a7ff-47f0-8c01-cf9c4283a851",
107119
"showTitle": false,
@@ -113,27 +125,58 @@
113125
"source": [
114126
"employee_177 = [(1, 100), (2, 200), (3, 300)]\n",
115127
"\n",
116-
"# Define the schema (column names)\n",
117128
"employee_columns_177 = [\"id\", \"salary\"]\n",
118129
"employee_df_177 = spark.createDataFrame(employee_177, employee_columns_177)\n",
119130
"employee_df_177.show()\n"
120131
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": 0,
136+
"metadata": {
137+
"application/vnd.databricks.v1+cell": {
138+
"cellMetadata": {
139+
"byteLimit": 2048000,
140+
"rowLimit": 10000
141+
},
142+
"inputWidgets": {},
143+
"nuid": "98e7fb56-c903-4347-8723-7a2f57c4d018",
144+
"showTitle": false,
145+
"tableResultSettingsMap": {},
146+
"title": ""
147+
}
148+
},
149+
"outputs": [],
150+
"source": [
151+
"windowSpec = Window.orderBy(col(\"salary\").cast('int').desc())\n",
152+
"employee_df_177.withColumn('getNthHighestSalary', rank().over(windowSpec)).filter(col('getNthHighestSalary') == '2').show()"
153+
]
121154
}
122155
],
123156
"metadata": {
124157
"application/vnd.databricks.v1+notebook": {
125-
"computePreferences": null,
158+
"computePreferences": {
159+
"hardware": {
160+
"accelerator": null,
161+
"gpuPoolId": null,
162+
"memory": null
163+
}
164+
},
126165
"dashboards": [],
127166
"environmentMetadata": {
128167
"base_environment": "",
129-
"client": "1"
168+
"environment_version": "2"
130169
},
170+
"inputWidgetPreferences": null,
131171
"language": "python",
132172
"notebookMetadata": {
133173
"pythonIndentUnit": 4
134174
},
135-
"notebookName": "177. Nth Highest Salary (Medium)",
175+
"notebookName": "177. Nth Highest Salary (Medium)-(Solved)",
136176
"widgets": {}
177+
},
178+
"language_info": {
179+
"name": "python"
137180
}
138181
},
139182
"nbformat": 4,

0 commit comments

Comments
 (0)