Skip to content

Commit 57c59b7

Browse files
authored
Added tasks 175, 176, 177, 178.
1 parent 88aca9a commit 57c59b7

File tree

15 files changed

+326
-0
lines changed

15 files changed

+326
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,13 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.5'
636636

637637
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
638638
|-|-|-|-|-|-
639+
| 0176 |[Second Highest Salary](src/main/kotlin/g0101_0200/s0176_second_highest_salary/script.sql)| Medium | Database | 225 | 73.10
639640

640641
#### Day 5 Union
641642

642643
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
643644
|-|-|-|-|-|-
645+
| 0175 |[Combine Two Tables](src/main/kotlin/g0101_0200/s0175_combine_two_tables/script.sql)| Easy | Database | 473 | 54.97
644646

645647
#### Day 6 Union
646648

@@ -1561,6 +1563,10 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.5'
15611563
| 0199 |[Binary Tree Right Side View](src/main/kotlin/g0101_0200/s0199_binary_tree_right_side_view/Solution.kt)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_II_Day_16_Tree, Level_2_Day_15_Tree | 194 | 92.89
15621564
| 0198 |[House Robber](src/main/kotlin/g0101_0200/s0198_house_robber/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_3, Level_2_Day_12_Dynamic_Programming, Udemy_Dynamic_Programming | 156 | 92.24
15631565
| 0189 |[Rotate Array](src/main/kotlin/g0101_0200/s0189_rotate_array/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Algorithm_I_Day_2_Two_Pointers, Udemy_Arrays | 483 | 86.95
1566+
| 0178 |[Rank Scores](src/main/kotlin/g0101_0200/s0178_rank_scores/script.sql)| Medium | Database | 290 | 66.73
1567+
| 0177 |[Nth Highest Salary](src/main/kotlin/g0101_0200/s0177_nth_highest_salary/script.sql)| Medium | Database | 342 | 71.87
1568+
| 0176 |[Second Highest Salary](src/main/kotlin/g0101_0200/s0176_second_highest_salary/script.sql)| Medium | Database, SQL_I_Day_4_Union_and_Select | 225 | 73.10
1569+
| 0175 |[Combine Two Tables](src/main/kotlin/g0101_0200/s0175_combine_two_tables/script.sql)| Easy | Database, SQL_I_Day_5_Union | 473 | 54.97
15641570
| 0174 |[Dungeon Game](src/main/kotlin/g0101_0200/s0174_dungeon_game/Solution.kt)| Hard | Array, Dynamic_Programming, Matrix | 300 | 66.67
15651571
| 0173 |[Binary Search Tree Iterator](src/main/kotlin/g0101_0200/s0173_binary_search_tree_iterator/BSTIterator.kt)| Medium | Tree, Binary_Tree, Stack, Design, Binary_Search_Tree, Iterator, Data_Structure_II_Day_17_Tree, Programming_Skills_II_Day_16, Level_2_Day_9_Binary_Search_Tree | 563 | 46.91
15661572
| 0172 |[Factorial Trailing Zeroes](src/main/kotlin/g0101_0200/s0172_factorial_trailing_zeroes/Solution.kt)| Medium | Top_Interview_Questions, Math, Udemy_Integers | 220 | 67.65

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies {
1818
testImplementation("org.junit.jupiter:junit-jupiter-api:[5.9.0,)")
1919
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:[5.9.0,)")
2020
testImplementation("org.hamcrest:hamcrest-core:[2.2,)")
21+
testImplementation("org.zapodot:embedded-db-junit-jupiter:[2.1.0,)")
2122
}
2223

2324
tasks.test {

pom-central.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,11 @@
155155
<version>[2.2,)</version>
156156
<scope>test</scope>
157157
</dependency>
158+
<dependency>
159+
<groupId>org.zapodot</groupId>
160+
<artifactId>embedded-db-junit-jupiter</artifactId>
161+
<version>[2.1.0,)</version>
162+
<scope>test</scope>
163+
</dependency>
158164
</dependencies>
159165
</project>

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,11 @@
149149
<version>[2.2,)</version>
150150
<scope>test</scope>
151151
</dependency>
152+
<dependency>
153+
<groupId>org.zapodot</groupId>
154+
<artifactId>embedded-db-junit-jupiter</artifactId>
155+
<version>[2.1.0,)</version>
156+
<scope>test</scope>
157+
</dependency>
152158
</dependencies>
153159
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
175\. Combine Two Tables
2+
3+
Easy
4+
5+
SQL Schema
6+
7+
Table: `Person`
8+
9+
+-------------+---------+ | Column Name | Type | +-------------+---------+ | personId | int | | lastName | varchar | | firstName | varchar | +-------------+---------+ personId is the primary key column for this table. This table contains information about the ID of some persons and their first and last names.
10+
11+
Table: `Address`
12+
13+
+-------------+---------+ | Column Name | Type | +-------------+---------+ | addressId | int | | personId | int | | city | varchar | | state | varchar | +-------------+---------+ addressId is the primary key column for this table. Each row of this table contains information about the city and state of one person with ID = PersonId.
14+
15+
Write an SQL query to report the first name, last name, city, and state of each person in the `Person` table. If the address of a `personId` is not present in the `Address` table, report `null` instead.
16+
17+
Return the result table in **any order**.
18+
19+
The query result format is in the following example.
20+
21+
**Example 1:**
22+
23+
**Input:** Person table: +----------+----------+-----------+ | personId | lastName | firstName | +----------+----------+-----------+ | 1 | Wang | Allen | | 2 | Alice | Bob | +----------+----------+-----------+ Address table: +-----------+----------+---------------+------------+ | addressId | personId | city | state | +-----------+----------+---------------+------------+ | 1 | 2 | New York City | New York | | 2 | 3 | Leetcode | California | +-----------+----------+---------------+------------+
24+
25+
**Output:** +-----------+----------+---------------+----------+ | firstName | lastName | city | state | +-----------+----------+---------------+----------+ | Allen | Wang | Null | Null | | Bob | Alice | New York City | New York | +-----------+----------+---------------+----------+
26+
27+
**Explanation:** There is no address in the address table for the personId = 1 so we return null in their city and state. addressId = 1 contains information about the address of personId = 2.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Write your MySQL query statement below
2+
# #Easy #Database #SQL_I_Day_5_Union #2022_10_12_Time_473_ms_(54.97%)_Space_0B_(100.00%)
3+
SELECT FirstName, LastName, City, State
4+
FROM Person LEFT JOIN Address USING (PersonId)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
176\. Second Highest Salary
2+
3+
Medium
4+
5+
SQL Schema
6+
7+
Table: `Employee`
8+
9+
+-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id is the primary key column for this table. Each row of this table contains information about the salary of an employee.
10+
11+
Write an SQL query to report the second highest salary from the `Employee` table. If there is no second highest salary, the query should report `null`.
12+
13+
The query result format is in the following example.
14+
15+
**Example 1:**
16+
17+
**Input:** Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+
18+
19+
**Output:** +---------------------+ | SecondHighestSalary | +---------------------+ | 200 | +---------------------+
20+
21+
**Example 2:**
22+
23+
**Input:** Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | +----+--------+
24+
25+
**Output:** +---------------------+ | SecondHighestSalary | +---------------------+ | null | +---------------------+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Write your MySQL query statement below
2+
# #Medium #Database #SQL_I_Day_4_Union_and_Select
3+
# #2022_07_10_Time_225_ms_(73.10%)_Space_0B_(100.00%)
4+
SELECT ifnull(
5+
(SELECT distinct(Salary)
6+
FROM Employee
7+
ORDER BY Salary DESC
8+
LIMIT 1
9+
OFFSET 1), NULL) SecondHighestSalary;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
177\. Nth Highest Salary
2+
3+
Medium
4+
5+
SQL Schema
6+
7+
Table: `Employee`
8+
9+
+-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id is the primary key column for this table. Each row of this table contains information about the salary of an employee.
10+
11+
Write an SQL query to report the <code>n<sup>th</sup></code> highest salary from the `Employee` table. If there is no <code>n<sup>th</sup></code> highest salary, the query should report `null`.
12+
13+
The query result format is in the following example.
14+
15+
**Example 1:**
16+
17+
**Input:** Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ n = 2
18+
19+
**Output:** +------------------------+ | getNthHighestSalary(2) | +------------------------+ | 200 | +------------------------+
20+
21+
**Example 2:**
22+
23+
**Input:** Employee table: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | +----+--------+ n = 2
24+
25+
**Output:** +------------------------+ | getNthHighestSalary(2) | +------------------------+ | null | +------------------------+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
2+
BEGIN
3+
DECLARE M INT;
4+
SET M=N-1;
5+
RETURN (
6+
# Write your MySQL query statement below.
7+
# #Medium #Database #2022_06_26_Time_342_ms_(71.87%)_Space_0B_(100.00%)
8+
SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M, 1
9+
);
10+
END

0 commit comments

Comments
 (0)