Skip to content

Commit 35c1901

Browse files
authored
Added tasks 1608-1800
1 parent bcd2e5d commit 35c1901

File tree

162 files changed

+13369
-4
lines changed
  • src/main/kotlin
    • g0001_0100/s0093_restore_ip_addresses
    • g0601_0700/s0638_shopping_offers
    • g1001_1100/s1039_minimum_score_triangulation_of_polygon
    • g1301_1400/s1378_replace_employee_id_with_the_unique_identifier
    • g1501_1600/s1517_find_users_with_valid_e_mails
    • g1601_1700
      • s1608_special_array_with_x_elements_greater_than_or_equal_x
      • s1609_even_odd_tree
      • s1610_maximum_number_of_visible_points
      • s1611_minimum_one_bit_operations_to_make_integers_zero
      • s1614_maximum_nesting_depth_of_the_parentheses
      • s1615_maximal_network_rank
      • s1616_split_two_strings_to_make_palindrome
      • s1617_count_subtrees_with_max_distance_between_cities
      • s1619_mean_of_array_after_removing_some_elements
      • s1620_coordinate_with_maximum_network_quality
      • s1621_number_of_sets_of_k_non_overlapping_line_segments
      • s1622_fancy_sequence
      • s1624_largest_substring_between_two_equal_characters
      • s1625_lexicographically_smallest_string_after_applying_operations
      • s1626_best_team_with_no_conflicts
      • s1627_graph_connectivity_with_threshold
      • s1629_slowest_key
      • s1630_arithmetic_subarrays
      • s1631_path_with_minimum_effort
      • s1632_rank_transform_of_a_matrix
      • s1633_percentage_of_users_attended_a_contest
      • s1636_sort_array_by_increasing_frequency
      • s1637_widest_vertical_area_between_two_points_containing_no_points
      • s1638_count_substrings_that_differ_by_one_character
      • s1639_number_of_ways_to_form_a_target_string_given_a_dictionary
      • s1640_check_array_formation_through_concatenation
      • s1641_count_sorted_vowel_strings
      • s1642_furthest_building_you_can_reach
      • s1643_kth_smallest_instructions
      • s1646_get_maximum_in_generated_array
      • s1647_minimum_deletions_to_make_character_frequencies_unique
      • s1648_sell_diminishing_valued_colored_balls
      • s1649_create_sorted_array_through_instructions
      • s1652_defuse_the_bomb
      • s1653_minimum_deletions_to_make_string_balanced
      • s1654_minimum_jumps_to_reach_home
      • s1655_distribute_repeating_integers
      • s1656_design_an_ordered_stream
      • s1657_determine_if_two_strings_are_close
      • s1658_minimum_operations_to_reduce_x_to_zero
      • s1659_maximize_grid_happiness
      • s1661_average_time_of_process_per_machine
      • s1662_check_if_two_string_arrays_are_equivalent
      • s1663_smallest_string_with_a_given_numeric_value
      • s1664_ways_to_make_a_fair_array
      • s1665_minimum_initial_energy_to_finish_tasks
      • s1667_fix_names_in_a_table
      • s1668_maximum_repeating_substring
      • s1669_merge_in_between_linked_lists
      • s1670_design_front_middle_back_queue
      • s1671_minimum_number_of_removals_to_make_mountain_array
      • s1672_richest_customer_wealth
      • s1673_find_the_most_competitive_subsequence
      • s1674_minimum_moves_to_make_array_complementary
      • s1675_minimize_deviation_in_array
      • s1678_goal_parser_interpretation
      • s1679_max_number_of_k_sum_pairs
      • s1680_concatenation_of_consecutive_binary_numbers
      • s1681_minimum_incompatibility
      • s1683_invalid_tweets
      • s1684_count_the_number_of_consistent_strings
      • s1685_sum_of_absolute_differences_in_a_sorted_array
      • s1686_stone_game_vi
      • s1687_delivering_boxes_from_storage_to_ports
      • s1688_count_of_matches_in_tournament
      • s1689_partitioning_into_minimum_number_of_deci_binary_numbers
      • s1690_stone_game_vii
      • s1691_maximum_height_by_stacking_cuboids
      • s1693_daily_leads_and_partners
      • s1694_reformat_phone_number
      • s1695_maximum_erasure_value
      • s1696_jump_game_vi
      • s1697_checking_existence_of_edge_length_limited_paths
      • s1700_number_of_students_unable_to_eat_lunch
    • g1701_1800
      • s1701_average_waiting_time
      • s1702_maximum_binary_string_after_change
      • s1703_minimum_adjacent_swaps_for_k_consecutive_ones
      • s1704_determine_if_string_halves_are_alike
      • s1705_maximum_number_of_eaten_apples
      • s1706_where_will_the_ball_fall
      • s1707_maximum_xor_with_an_element_from_array
      • s1710_maximum_units_on_a_truck
      • s1711_count_good_meals
      • s1712_ways_to_split_array_into_three_subarrays
      • s1713_minimum_operations_to_make_a_subsequence
      • s1716_calculate_money_in_leetcode_bank
      • s1717_maximum_score_from_removing_substrings
      • s1718_construct_the_lexicographically_largest_valid_sequence
      • s1719_number_of_ways_to_reconstruct_a_tree
      • s1720_decode_xored_array
      • s1721_swapping_nodes_in_a_linked_list
      • s1722_minimize_hamming_distance_after_swap_operations
      • s1723_find_minimum_time_to_finish_all_jobs
      • s1725_number_of_rectangles_that_can_form_the_largest_square
      • s1726_tuple_with_same_product
      • s1727_largest_submatrix_with_rearrangements
      • s1728_cat_and_mouse_ii
      • s1729_find_followers_count
      • s1731_the_number_of_employees_which_report_to_each_employee
      • s1732_find_the_highest_altitude
      • s1733_minimum_number_of_people_to_teach
      • s1734_decode_xored_permutation
      • s1735_count_ways_to_make_array_with_product
      • s1736_latest_time_by_replacing_hidden_digits
      • s1737_change_minimum_characters_to_satisfy_one_of_three_conditions
      • s1738_find_kth_largest_xor_coordinate_value
      • s1739_building_boxes
      • s1741_find_total_time_spent_by_each_employee
      • s1742_maximum_number_of_balls_in_a_box
      • s1743_restore_the_array_from_adjacent_pairs
      • s1744_can_you_eat_your_favorite_candy_on_your_favorite_day
      • s1745_palindrome_partitioning_iv
      • s1748_sum_of_unique_elements
      • s1749_maximum_absolute_sum_of_any_subarray
      • s1750_minimum_length_of_string_after_deleting_similar_ends
      • s1751_maximum_number_of_events_that_can_be_attended_ii
      • s1752_check_if_array_is_sorted_and_rotated
      • s1753_maximum_score_from_removing_stones
      • s1754_largest_merge_of_two_strings
      • s1755_closest_subsequence_sum
      • s1757_recyclable_and_low_fat_products
      • s1758_minimum_changes_to_make_alternating_binary_string
      • s1759_count_number_of_homogenous_substrings
      • s1760_minimum_limit_of_balls_in_a_bag
      • s1761_minimum_degree_of_a_connected_trio_in_a_graph
      • s1763_longest_nice_substring
      • s1764_form_array_by_concatenating_subarrays_of_another_array
      • s1765_map_of_highest_peak
      • s1766_tree_of_coprimes
      • s1768_merge_strings_alternately
      • s1769_minimum_number_of_operations_to_move_all_balls_to_each_box
      • s1770_maximum_score_from_performing_multiplication_operations
      • s1771_maximize_palindrome_length_from_subsequences
      • s1773_count_items_matching_a_rule
      • s1774_closest_dessert_cost
      • s1775_equal_sum_arrays_with_minimum_number_of_operations
      • s1776_car_fleet_ii
      • s1779_find_nearest_point_that_has_the_same_x_or_y_coordinate
      • s1780_check_if_number_is_a_sum_of_powers_of_three
      • s1781_sum_of_beauty_of_all_substrings
      • s1782_count_pairs_of_nodes
      • s1784_check_if_binary_string_has_at_most_one_segment_of_ones
      • s1785_minimum_elements_to_add_to_form_a_given_sum
      • s1786_number_of_restricted_paths_from_first_to_last_node
      • s1787_make_the_xor_of_all_segments_equal_to_zero
      • s1789_primary_department_for_each_employee
      • s1790_check_if_one_string_swap_can_make_strings_equal
      • s1791_find_center_of_star_graph
      • s1792_maximum_average_pass_ratio
      • s1793_maximum_score_of_a_good_subarray
      • s1795_rearrange_products_table
      • s1796_second_largest_digit_in_a_string
      • s1797_design_authentication_manager
      • s1798_maximum_number_of_consecutive_values_you_can_make
      • s1799_maximize_score_after_n_operations
      • s1800_maximum_ascending_subarray_sum

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+13369
-4
lines changed

README.md

Lines changed: 179 additions & 1 deletion
Large diffs are not rendered by default.

src/main/kotlin/g0001_0100/s0093_restore_ip_addresses/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Given a string `s` containing only digits, return _all possible valid IP address
3737
## Solution
3838

3939
```kotlin
40-
class Solution() {
40+
class Solution {
4141
fun restoreIpAddresses(s: String): List<String> {
4242
val results: MutableList<String> = ArrayList()
4343
step(s, 0, IntArray(4), 0, results)

src/main/kotlin/g0601_0700/s0638_shopping_offers/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ You cannot add more items, though only $9 for 2A ,2B and 1C.
5151
## Solution
5252

5353
```kotlin
54-
class Solution() {
54+
class Solution {
5555
fun shoppingOffers(
5656
price: List<Int>,
5757
special: List<List<Int>>,

src/main/kotlin/g1001_1100/s1039_minimum_score_triangulation_of_polygon/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Return _the smallest possible total score that you can achieve with some triangu
5050
## Solution
5151

5252
```kotlin
53-
class Solution() {
53+
class Solution {
5454
private val dp = Array(101) { IntArray(101) }
5555
fun minScoreTriangulation(values: IntArray): Int {
5656
val n = values.size
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 1378\. Replace Employee ID With The Unique Identifier
5+
6+
Easy
7+
8+
SQL Schema
9+
10+
Table: `Employees`
11+
12+
+---------------+---------+
13+
| Column Name | Type |
14+
+---------------+---------+
15+
| id | int |
16+
| name | varchar |
17+
+---------------+---------+
18+
id is the primary key for this table.
19+
Each row of this table contains the id and the name of an employee in a company.
20+
21+
Table: `EmployeeUNI`
22+
23+
+---------------+---------+
24+
| Column Name | Type |
25+
+---------------+---------+
26+
| id | int |
27+
| unique_id | int |
28+
+---------------+---------+
29+
(id, unique_id) is the primary key for this table.
30+
Each row of this table contains the id and the corresponding unique id of an employee in the company.
31+
32+
Write an SQL query to show the **unique ID** of each user, If a user does not have a unique ID replace just show `null`.
33+
34+
Return the result table in **any** order.
35+
36+
The query result format is in the following example.
37+
38+
**Example 1:**
39+
40+
**Input:**,
41+
42+
Employees table:
43+
+----+----------+
44+
| id | name |
45+
+----+----------+
46+
| 1 | Alice |
47+
| 7 | Bob |
48+
| 11 | Meir |
49+
| 90 | Winston |
50+
| 3 | Jonathan |
51+
+----+----------+
52+
53+
EmployeeUNI table:
54+
+----+-----------+
55+
| id | unique_id |
56+
+----+-----------+
57+
| 3 | 1 |
58+
| 11 | 2 |
59+
| 90 | 3 |
60+
+----+-----------+
61+
62+
**Output:**
63+
64+
+-----------+----------+
65+
| unique_id | name |
66+
+-----------+----------+
67+
| null | Alice |
68+
| null | Bob |
69+
| 2 | Meir |
70+
| 3 | Winston |
71+
| 1 | Jonathan |
72+
+-----------+----------+
73+
74+
**Explanation:**
75+
76+
Alice and Bob do not have a unique ID, We will show null instead.
77+
78+
The unique ID of Meir is 2.
79+
80+
The unique ID of Winston is 3.
81+
82+
The unique ID of Jonathan is 1.
83+
84+
## Solution
85+
86+
```sql
87+
# Write your MySQL query statement below
88+
select u.unique_id, e.name
89+
from Employees e
90+
left join EmployeeUNI u
91+
on e.id = u.id;
92+
```
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 1517\. Find Users With Valid E-Mails
5+
6+
Easy
7+
8+
SQL Schema
9+
10+
Table: `Users`
11+
12+
+---------------+---------+
13+
| Column Name | Type |
14+
+---------------+---------+
15+
| user_id | int |
16+
| name | varchar |
17+
| mail | varchar |
18+
+---------------+---------+
19+
user_id is the primary key for this table.
20+
This table contains information of the users signed up in a website. Some e-mails are invalid.
21+
22+
Write an SQL query to find the users who have **valid emails**.
23+
24+
A valid e-mail has a prefix name and a domain where:
25+
26+
* **The prefix name** is a string that may contain letters (upper or lower case), digits, underscore `'_'`, period `'.'`, and/or dash `'-'`. The prefix name **must** start with a letter.
27+
* **The domain** is `'@leetcode.com'`.
28+
29+
Return the result table in **any order**.
30+
31+
The query result format is in the following example.
32+
33+
**Example 1:**
34+
35+
**Input:**
36+
37+
Users table:
38+
+---------+-----------+-------------------------+
39+
| user_id | name | mail |
40+
+---------+-----------+-------------------------+
41+
| 1 | Winston | winston@leetcode.com |
42+
| 2 | Jonathan | jonathanisgreat |
43+
| 3 | Annabelle | bella-@leetcode.com |
44+
| 4 | Sally | sally.come@leetcode.com |
45+
| 5 | Marwan | quarz#2020@leetcode.com |
46+
| 6 | David | david69@gmail.com |
47+
| 7 | Shapiro | .shapo@leetcode.com |
48+
+---------+-----------+-------------------------+
49+
50+
**Output:**
51+
52+
+---------+-----------+-------------------------+
53+
| user_id | name | mail |
54+
+---------+-----------+-------------------------+
55+
| 1 | Winston | winston@leetcode.com |
56+
| 3 | Annabelle | bella-@leetcode.com |
57+
| 4 | Sally | sally.come@leetcode.com |
58+
+---------+-----------+-------------------------+
59+
60+
**Explanation:**
61+
62+
The mail of user 2 does not have a domain.
63+
64+
The mail of user 5 has the # sign which is not allowed.
65+
66+
The mail of user 6 does not have the leetcode domain.
67+
68+
The mail of user 7 starts with a period.
69+
70+
## Solution
71+
72+
```sql
73+
# Write your MySQL query statement below
74+
select * from Users
75+
where mail REGEXP '^[a-zA-Z][a-zA-Z0-9_.-]*@leetcode.com' and mail LIKE '%@leetcode.com'
76+
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 1608\. Special Array With X Elements Greater Than or Equal X
5+
6+
Easy
7+
8+
You are given an array `nums` of non-negative integers. `nums` is considered **special** if there exists a number `x` such that there are **exactly** `x` numbers in `nums` that are **greater than or equal to** `x`.
9+
10+
Notice that `x` **does not** have to be an element in `nums`.
11+
12+
Return `x` _if the array is **special**, otherwise, return_ `-1`. It can be proven that if `nums` is special, the value for `x` is **unique**.
13+
14+
**Example 1:**
15+
16+
**Input:** nums = [3,5]
17+
18+
**Output:** 2
19+
20+
**Explanation:** There are 2 values (3 and 5) that are greater than or equal to 2.
21+
22+
**Example 2:**
23+
24+
**Input:** nums = [0,0]
25+
26+
**Output:** -1
27+
28+
**Explanation:** No numbers fit the criteria for x.
29+
30+
If x = 0, there should be 0 numbers >= x, but there are 2.
31+
32+
If x = 1, there should be 1 number >= x, but there are 0.
33+
34+
If x = 2, there should be 2 numbers >= x, but there are 0.
35+
36+
x cannot be greater since there are only 2 numbers in nums.
37+
38+
**Example 3:**
39+
40+
**Input:** nums = [0,4,3,0,4]
41+
42+
**Output:** 3
43+
44+
**Explanation:** There are 3 values that are greater than or equal to 3.
45+
46+
**Constraints:**
47+
48+
* `1 <= nums.length <= 100`
49+
* `0 <= nums[i] <= 1000`
50+
51+
## Solution
52+
53+
```kotlin
54+
class Solution {
55+
fun specialArray(nums: IntArray): Int {
56+
nums.sort()
57+
val max = nums[nums.size - 1]
58+
for (x in 1..max) {
59+
var found = 0
60+
var i = nums.size - 1
61+
while (i >= 0 && nums[i] >= x) {
62+
i--
63+
found++
64+
}
65+
if (found == x) {
66+
return x
67+
}
68+
}
69+
return -1
70+
}
71+
}
72+
```
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 1609\. Even Odd Tree
5+
6+
Medium
7+
8+
A binary tree is named **Even-Odd** if it meets the following conditions:
9+
10+
* The root of the binary tree is at level index `0`, its children are at level index `1`, their children are at level index `2`, etc.
11+
* For every **even-indexed** level, all nodes at the level have **odd** integer values in **strictly increasing** order (from left to right).
12+
* For every **odd-indexed** level, all nodes at the level have **even** integer values in **strictly decreasing** order (from left to right).
13+
14+
Given the `root` of a binary tree, _return_ `true` _if the binary tree is **Even-Odd**, otherwise return_ `false`_._
15+
16+
**Example 1:**
17+
18+
![](https://assets.leetcode.com/uploads/2020/09/15/sample_1_1966.png)
19+
20+
**Input:** root = [1,10,4,3,null,7,9,12,8,6,null,null,2]
21+
22+
**Output:** true
23+
24+
**Explanation:** The node values on each level are:
25+
26+
Level 0: [1]
27+
28+
Level 1: [10,4]
29+
30+
Level 2: [3,7,9]
31+
32+
Level 3: [12,8,6,2]
33+
34+
Since levels 0 and 2 are all odd and increasing and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.
35+
36+
**Example 2:**
37+
38+
![](https://assets.leetcode.com/uploads/2020/09/15/sample_2_1966.png)
39+
40+
**Input:** root = [5,4,2,3,3,7]
41+
42+
**Output:** false
43+
44+
**Explanation:** The node values on each level are:
45+
46+
Level 0: [5]
47+
48+
Level 1: [4,2]
49+
50+
Level 2: [3,3,7]
51+
52+
Node values in level 2 must be in strictly increasing order, so the tree is not Even-Odd.
53+
54+
**Example 3:**
55+
56+
![](https://assets.leetcode.com/uploads/2020/09/22/sample_1_333_1966.png)
57+
58+
**Input:** root = [5,9,1,3,5,7]
59+
60+
**Output:** false
61+
62+
**Explanation:** Node values in the level 1 should be even integers.
63+
64+
**Constraints:**
65+
66+
* The number of nodes in the tree is in the range <code>[1, 10<sup>5</sup>]</code>.
67+
* <code>1 <= Node.val <= 10<sup>6</sup></code>
68+
69+
## Solution
70+
71+
```kotlin
72+
import com_github_leetcode.TreeNode
73+
74+
/*
75+
* Example:
76+
* var ti = TreeNode(5)
77+
* var v = ti.`val`
78+
* Definition for a binary tree node.
79+
* class TreeNode(var `val`: Int) {
80+
* var left: TreeNode? = null
81+
* var right: TreeNode? = null
82+
* }
83+
*/
84+
class Solution {
85+
private val comp: MutableList<Int> = ArrayList()
86+
87+
fun isEvenOddTree(root: TreeNode?): Boolean {
88+
return find(root, 0)
89+
}
90+
91+
private fun find(root: TreeNode?, height: Int): Boolean {
92+
if (root == null) {
93+
return true
94+
}
95+
if (height % 2 == 0 && root.`val` % 2 == 0 || height % 2 == 1 && root.`val` % 2 == 1) {
96+
return false
97+
}
98+
if (comp.size == height) {
99+
comp.add(root.`val`)
100+
} else {
101+
if (height % 2 == 0) {
102+
if (comp[height] >= root.`val`) {
103+
return false
104+
} else {
105+
comp[height] = root.`val`
106+
}
107+
} else {
108+
if (comp[height] <= root.`val`) {
109+
return false
110+
} else {
111+
comp[height] = root.`val`
112+
}
113+
}
114+
}
115+
return find(root.left, height + 1) && find(root.right, height + 1)
116+
}
117+
}
118+
```

0 commit comments

Comments
 (0)