Skip to content

Commit 419ea47

Browse files
authored
Added tasks 179, 180, 181, 182.
1 parent 25ddfd5 commit 419ea47

File tree

13 files changed

+377
-0
lines changed

13 files changed

+377
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.5'
668668

669669
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
670670
|-|-|-|-|-|-
671+
| 0182 |[Duplicate Emails](src/main/kotlin/g0101_0200/s0182_duplicate_emails/script.sql)| Easy | Database | 303 | 92.08
671672

672673
### Level 1
673674

@@ -1563,6 +1564,10 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.5'
15631564
| 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
15641565
| 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
15651566
| 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
1567+
| 0182 |[Duplicate Emails](src/main/kotlin/g0101_0200/s0182_duplicate_emails/script.sql)| Easy | Database, SQL_I_Day_10_Where | 303 | 92.08
1568+
| 0181 |[Employees Earning More Than Their Managers](src/main/kotlin/g0101_0200/s0181_employees_earning_more_than_their_managers/script.sql)| Easy | Database | 315 | 94.44
1569+
| 0180 |[Consecutive Numbers](src/main/kotlin/g0101_0200/s0180_consecutive_numbers/script.sql)| Medium | Database | 550 | 48.44
1570+
| 0179 |[Largest Number](src/main/kotlin/g0101_0200/s0179_largest_number/Solution.kt)| Medium | Top_Interview_Questions, String, Sorting, Greedy | 380 | 43.40
15661571
| 0178 |[Rank Scores](src/main/kotlin/g0101_0200/s0178_rank_scores/script.sql)| Medium | Database | 290 | 66.73
15671572
| 0177 |[Nth Highest Salary](src/main/kotlin/g0101_0200/s0177_nth_highest_salary/script.sql)| Medium | Database | 342 | 71.87
15681573
| 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
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package g0101_0200.s0179_largest_number
2+
3+
// #Medium #Top_Interview_Questions #String #Sorting #Greedy
4+
// #2022_10_13_Time_380_ms_(43.40%)_Space_39.9_MB_(60.38%)
5+
6+
import java.util.Arrays
7+
8+
class Solution {
9+
fun largestNumber(nums: IntArray): String {
10+
val n = nums.size
11+
val s = arrayOfNulls<String>(n)
12+
for (i in 0 until n) {
13+
s[i] = nums[i].toString()
14+
}
15+
Arrays.sort(s) { a: String?, b: String? ->
16+
(b + a).compareTo(
17+
a + b
18+
)
19+
}
20+
val sb = StringBuilder()
21+
for (str in s) {
22+
sb.append(str)
23+
}
24+
val result = sb.toString()
25+
return if (result.startsWith("0")) "0" else result
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
179\. Largest Number
2+
3+
Medium
4+
5+
Given a list of non-negative integers `nums`, arrange them such that they form the largest number and return it.
6+
7+
Since the result may be very large, so you need to return a string instead of an integer.
8+
9+
**Example 1:**
10+
11+
**Input:** nums = [10,2]
12+
13+
**Output:** "210"
14+
15+
**Example 2:**
16+
17+
**Input:** nums = [3,30,34,5,9]
18+
19+
**Output:** "9534330"
20+
21+
**Constraints:**
22+
23+
* `1 <= nums.length <= 100`
24+
* <code>0 <= nums[i] <= 10<sup>9</sup></code>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
180\. Consecutive Numbers
2+
3+
Medium
4+
5+
SQL Schema
6+
7+
Table: `Logs`
8+
9+
+-------------+---------+
10+
| Column Name | Type |
11+
+-------------+---------+
12+
| id | int |
13+
| num | varchar |
14+
+-------------+---------+
15+
id is the primary key for this table.
16+
17+
Write an SQL query to find all numbers that appear at least three times consecutively.
18+
19+
Return the result table in **any order**.
20+
21+
The query result format is in the following example.
22+
23+
**Example 1:**
24+
25+
**Input:**
26+
27+
Logs table:
28+
+----+-----+
29+
| id | num |
30+
+----+-----+
31+
| 1 | 1 |
32+
| 2 | 1 |
33+
| 3 | 1 |
34+
| 4 | 2 |
35+
| 5 | 1 |
36+
| 6 | 2 |
37+
| 7 | 2 |
38+
+----+-----+
39+
40+
**Output:**
41+
42+
+-----------------+
43+
| ConsecutiveNums |
44+
+-----------------+
45+
| 1 |
46+
+-----------------+
47+
48+
**Explanation:** 1 is the only number that appears consecutively for at least three times.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write your MySQL query statement below
2+
# #Medium #Database #2022_06_26_Time_550_ms_(48.44%)_Space_0B_(100.00%)
3+
select distinct num as ConsecutiveNums from
4+
(select num, lag(num,1) over(order by id) as l1, lag(num,2) over(order by id) as l2
5+
from Logs) con_thr
6+
where num = l1 and num = l2
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
181\. Employees Earning More Than Their Managers
2+
3+
Easy
4+
5+
SQL Schema
6+
7+
Table: `Employee`
8+
9+
+-------------+---------+
10+
| Column Name | Type |
11+
+-------------+---------+
12+
| id | int |
13+
| name | varchar |
14+
| salary | int |
15+
| managerId | int |
16+
+-------------+---------+
17+
id is the primary key column for this table.
18+
Each row of this table indicates the ID of an employee, their name, salary, and the ID of their manager.
19+
20+
Write an SQL query to find the employees who earn more than their managers.
21+
22+
Return the result table in **any order**.
23+
24+
The query result format is in the following example.
25+
26+
**Example 1:**
27+
28+
**Input:**
29+
30+
Employee table:
31+
+----+-------+--------+-----------+
32+
| id | name | salary | managerId |
33+
+----+-------+--------+-----------+
34+
| 1 | Joe | 70000 | 3 |
35+
| 2 | Henry | 80000 | 4 |
36+
| 3 | Sam | 60000 | Null |
37+
| 4 | Max | 90000 | Null |
38+
+----+-------+--------+-----------+
39+
40+
**Output:**
41+
42+
+----------+
43+
| Employee |
44+
+----------+
45+
| Joe |
46+
+----------+
47+
48+
**Explanation:** Joe is the only employee who earns more than his manager.
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 #2022_06_27_Time_315_ms_(94.44%)_Space_0B_(100.00%)
3+
select a.Name as Employee from Employee a left join Employee b on a.ManagerId=b.Id
4+
where a.Salary > b.Salary and a.ManagerId is not null
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
182\. Duplicate Emails
2+
3+
Easy
4+
5+
SQL Schema
6+
7+
Table: `Person`
8+
9+
+-------------+---------+
10+
| Column Name | Type |
11+
+-------------+---------+
12+
| id | int |
13+
| email | varchar |
14+
+-------------+---------+
15+
id is the primary key column for this table.
16+
Each row of this table contains an email. The emails will not contain uppercase letters.
17+
18+
Write an SQL query to report all the duplicate emails.
19+
20+
Return the result table in **any order**.
21+
22+
The query result format is in the following example.
23+
24+
**Example 1:**
25+
26+
**Input:**
27+
28+
Person table:
29+
+----+---------+
30+
| id | email |
31+
+----+---------+
32+
| 1 | a@b.com |
33+
| 2 | c@d.com |
34+
| 3 | a@b.com |
35+
+----+---------+
36+
37+
**Output:**
38+
39+
+---------+
40+
| Email |
41+
+---------+
42+
| a@b.com |
43+
+---------+
44+
45+
**Explanation:** a@b.com is repeated two times.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Write your MySQL query statement below
2+
# #Easy #Database #SQL_I_Day_10_Where #2022_06_27_Time_303_ms_(92.08%)_Space_0B_(100.00%)
3+
SELECT Email FROM Person GROUP BY Email HAVING COUNT(Email) > 1;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package g0101_0200.s0179_largest_number
2+
3+
import org.hamcrest.CoreMatchers.equalTo
4+
import org.hamcrest.MatcherAssert.assertThat
5+
import org.junit.jupiter.api.Test
6+
7+
internal class SolutionTest {
8+
@Test
9+
fun largestNumber() {
10+
assertThat(Solution().largestNumber(intArrayOf(10, 2)), equalTo("210"))
11+
}
12+
13+
@Test
14+
fun largestNumber2() {
15+
assertThat(Solution().largestNumber(intArrayOf(3, 30, 34, 5, 9)), equalTo("9534330"))
16+
}
17+
}

0 commit comments

Comments
 (0)