Skip to content

Commit ed2282a

Browse files
authored
Added tasks 1851-1900
1 parent db0272d commit ed2282a

File tree

122 files changed

+4423
-0
lines changed

Some content is hidden

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

122 files changed

+4423
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.13'
10041004

10051005
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10061006
|-|-|-|-|-|-
1007+
| 1855 |[Maximum Distance Between a Pair of Values](src/main/kotlin/g1801_1900/s1855_maximum_distance_between_a_pair_of_values/Solution.kt)| Medium | Array, Greedy, Binary_Search, Two_Pointers | 541 | 14.29
10071008
| 0033 |[Search in Rotated Sorted Array](src.save/main/kotlin/g0001_0100/s0033_search_in_rotated_sorted_array/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search | 184 | 86.08
10081009

10091010
#### Day 12
@@ -1026,6 +1027,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.13'
10261027
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10271028
|-|-|-|-|-|-
10281029
| 0658 |[Find K Closest Elements](src.save/main/kotlin/g0601_0700/s0658_find_k_closest_elements/Solution.kt)| Medium | Array, Sorting, Binary_Search, Two_Pointers, Heap_Priority_Queue | 375 | 95.16
1030+
| 1894 |[Find the Student that Will Replace the Chalk](src/main/kotlin/g1801_1900/s1894_find_the_student_that_will_replace_the_chalk/Solution.kt)| Medium | Array, Binary_Search, Simulation, Prefix_Sum | 520 | 50.00
10291031

10301032
#### Day 3
10311033

@@ -1052,6 +1054,8 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.13'
10521054

10531055
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10541056
|-|-|-|-|-|-
1057+
| 1898 |[Maximum Number of Removable Characters](src/main/kotlin/g1801_1900/s1898_maximum_number_of_removable_characters/Solution.kt)| Medium | Array, String, Binary_Search | 636 | 100.00
1058+
| 1870 |[Minimum Speed to Arrive on Time](src/main/kotlin/g1801_1900/s1870_minimum_speed_to_arrive_on_time/Solution.kt)| Medium | Array, Binary_Search | 628 | 50.00
10551059

10561060
#### Day 7
10571061

@@ -1449,6 +1453,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.13'
14491453
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
14501454
|-|-|-|-|-|-
14511455
| 0048 |[Rotate Image](src.save/main/kotlin/g0001_0100/s0048_rotate_image/Solution.kt)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix | 287 | 46.50
1456+
| 1886 |[Determine Whether Matrix Can Be Obtained By Rotation](src/main/kotlin/g1801_1900/s1886_determine_whether_matrix_can_be_obtained_by_rotation/Solution.kt)| Easy | Array, Matrix | 147 | 85.71
14521457

14531458
#### Day 8
14541459

@@ -1661,6 +1666,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.13'
16611666

16621667
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
16631668
|-|-|-|-|-|-
1669+
| 1873 |[Calculate Special Bonus](src/main/kotlin/g1801_1900/s1873_calculate_special_bonus/script.sql)| Easy | Database | 1321 | 33.12
16641670
| 0627 |[Swap Salary](src.save/main/kotlin/g0601_0700/s0627_swap_salary/script.sql)| Easy | Database | 400 | 51.04
16651671
| 0196 |[Delete Duplicate Emails](src.save/main/kotlin/g0101_0200/s0196_delete_duplicate_emails/script.sql)| Easy | Database | 593 | 94.17
16661672

@@ -1710,6 +1716,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.13'
17101716
|-|-|-|-|-|-
17111717
| 0586 |[Customer Placing the Largest Number of Orders](src.save/main/kotlin/g0501_0600/s0586_customer_placing_the_largest_number_of_orders/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 768 | 44.85
17121718
| 0511 |[Game Play Analysis I](src.save/main/kotlin/g0501_0600/s0511_game_play_analysis_i/script.sql)| Easy | LeetCode_Curated_SQL_70, Database | 790 | 45.04
1719+
| 1890 |[The Latest Login in 2020](src/main/kotlin/g1801_1900/s1890_the_latest_login_in_2020/script.sql)| Easy | Database | 1486 | 22.18
17131720
| 1741 |[Find Total Time Spent by Each Employee](src.save/main/kotlin/g1701_1800/s1741_find_total_time_spent_by_each_employee/script.sql)| Easy | Database | 1101 | 51.40
17141721

17151722
#### Day 9 Control of Flow
@@ -1916,6 +1923,46 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.13'
19161923
| 1904 |[The Number of Full Rounds You Have Played](src/main/kotlin/g1901_2000/s1904_the_number_of_full_rounds_you_have_played/Solution.kt)| Medium | String, Math | 149 | 100.00
19171924
| 1903 |[Largest Odd Number in String](src/main/kotlin/g1901_2000/s1903_largest_odd_number_in_string/Solution.kt)| Easy | String, Math, Greedy | 256 | 75.00
19181925
| 1901 |[Find a Peak Element II](src/main/kotlin/g1901_2000/s1901_find_a_peak_element_ii/Solution.kt)| Medium | Array, Binary_Search, Matrix, Divide_and_Conquer, Binary_Search_II_Day_17 | 726 | 100.00
1926+
| 1900 |[The Earliest and Latest Rounds Where Players Compete](src/main/kotlin/g1801_1900/s1900_the_earliest_and_latest_rounds_where_players_compete/Solution.kt)| Hard | Dynamic_Programming, Memoization | 142 | 100.00
1927+
| 1899 |[Merge Triplets to Form Target Triplet](src/main/kotlin/g1801_1900/s1899_merge_triplets_to_form_target_triplet/Solution.kt)| Medium | Array, Greedy | 954 | 71.43
1928+
| 1898 |[Maximum Number of Removable Characters](src/main/kotlin/g1801_1900/s1898_maximum_number_of_removable_characters/Solution.kt)| Medium | Array, String, Binary_Search, Binary_Search_II_Day_6 | 636 | 100.00
1929+
| 1897 |[Redistribute Characters to Make All Strings Equal](src/main/kotlin/g1801_1900/s1897_redistribute_characters_to_make_all_strings_equal/Solution.kt)| Easy | String, Hash_Table, Counting | 179 | 100.00
1930+
| 1896 |[Minimum Cost to Change the Final Value of Expression](src/main/kotlin/g1801_1900/s1896_minimum_cost_to_change_the_final_value_of_expression/Solution.kt)| Hard | String, Dynamic_Programming, Math, Stack | 252 | 100.00
1931+
| 1895 |[Largest Magic Square](src/main/kotlin/g1801_1900/s1895_largest_magic_square/Solution.kt)| Medium | Array, Matrix, Prefix_Sum | 202 | 100.00
1932+
| 1894 |[Find the Student that Will Replace the Chalk](src/main/kotlin/g1801_1900/s1894_find_the_student_that_will_replace_the_chalk/Solution.kt)| Medium | Array, Binary_Search, Simulation, Prefix_Sum, Binary_Search_II_Day_2 | 520 | 50.00
1933+
| 1893 |[Check if All the Integers in a Range Are Covered](src/main/kotlin/g1801_1900/s1893_check_if_all_the_integers_in_a_range_are_covered/Solution.kt)| Easy | Array, Hash_Table, Prefix_Sum | 140 | 100.00
1934+
| 1890 |[The Latest Login in 2020](src/main/kotlin/g1801_1900/s1890_the_latest_login_in_2020/script.sql)| Easy | Database, SQL_I_Day_8_Function | 1486 | 22.18
1935+
| 1889 |[Minimum Space Wasted From Packaging](src/main/kotlin/g1801_1900/s1889_minimum_space_wasted_from_packaging/Solution.kt)| Hard | Array, Sorting, Binary_Search, Prefix_Sum | 910 | 100.00
1936+
| 1888 |[Minimum Number of Flips to Make the Binary String Alternating](src/main/kotlin/g1801_1900/s1888_minimum_number_of_flips_to_make_the_binary_string_alternating/Solution.kt)| Medium | String, Greedy | 259 | 87.50
1937+
| 1887 |[Reduction Operations to Make the Array Elements Equal](src/main/kotlin/g1801_1900/s1887_reduction_operations_to_make_the_array_elements_equal/Solution.kt)| Medium | Array, Sorting | 457 | 100.00
1938+
| 1886 |[Determine Whether Matrix Can Be Obtained By Rotation](src/main/kotlin/g1801_1900/s1886_determine_whether_matrix_can_be_obtained_by_rotation/Solution.kt)| Easy | Array, Matrix, Programming_Skills_II_Day_7 | 147 | 85.71
1939+
| 1884 |[Egg Drop With 2 Eggs and N Floors](src/main/kotlin/g1801_1900/s1884_egg_drop_with_2_eggs_and_n_floors/Solution.kt)| Medium | Dynamic_Programming, Math | 130 | 100.00
1940+
| 1883 |[Minimum Skips to Arrive at Meeting On Time](src/main/kotlin/g1801_1900/s1883_minimum_skips_to_arrive_at_meeting_on_time/Solution.kt)| Hard | Array, Dynamic_Programming | 278 | 100.00
1941+
| 1882 |[Process Tasks Using Servers](src/main/kotlin/g1801_1900/s1882_process_tasks_using_servers/Solution.kt)| Medium | Array, Heap_Priority_Queue | 1085 | 100.00
1942+
| 1881 |[Maximum Value after Insertion](src/main/kotlin/g1801_1900/s1881_maximum_value_after_insertion/Solution.kt)| Medium | String, Greedy | 362 | 100.00
1943+
| 1880 |[Check if Word Equals Summation of Two Words](src/main/kotlin/g1801_1900/s1880_check_if_word_equals_summation_of_two_words/Solution.kt)| Easy | String | 139 | 80.00
1944+
| 1879 |[Minimum XOR Sum of Two Arrays](src/main/kotlin/g1801_1900/s1879_minimum_xor_sum_of_two_arrays/Solution.kt)| Hard | Array, Dynamic_Programming, Bit_Manipulation, Bitmask | 173 | 100.00
1945+
| 1878 |[Get Biggest Three Rhombus Sums in a Grid](src/main/kotlin/g1801_1900/s1878_get_biggest_three_rhombus_sums_in_a_grid/Solution.kt)| Medium | Array, Math, Sorting, Matrix, Heap_Priority_Queue, Prefix_Sum | 326 | 100.00
1946+
| 1877 |[Minimize Maximum Pair Sum in Array](src/main/kotlin/g1801_1900/s1877_minimize_maximum_pair_sum_in_array/Solution.kt)| Medium | Array, Sorting, Greedy, Two_Pointers | 668 | 50.00
1947+
| 1876 |[Substrings of Size Three with Distinct Characters](src/main/kotlin/g1801_1900/s1876_substrings_of_size_three_with_distinct_characters/Solution.kt)| Easy | String, Hash_Table, Counting, Sliding_Window | 144 | 91.67
1948+
| 1873 |[Calculate Special Bonus](src/main/kotlin/g1801_1900/s1873_calculate_special_bonus/script.sql)| Easy | Database, SQL_I_Day_2_Select_and_Order | 1321 | 33.12
1949+
| 1872 |[Stone Game VIII](src/main/kotlin/g1801_1900/s1872_stone_game_viii/Solution.kt)| Hard | Array, Dynamic_Programming, Math, Prefix_Sum, Game_Theory | 569 | 100.00
1950+
| 1871 |[Jump Game VII](src/main/kotlin/g1801_1900/s1871_jump_game_vii/Solution.kt)| Medium | String, Two_Pointers, Prefix_Sum | 247 | 100.00
1951+
| 1870 |[Minimum Speed to Arrive on Time](src/main/kotlin/g1801_1900/s1870_minimum_speed_to_arrive_on_time/Solution.kt)| Medium | Array, Binary_Search, Binary_Search_II_Day_6 | 628 | 50.00
1952+
| 1869 |[Longer Contiguous Segments of Ones than Zeros](src/main/kotlin/g1801_1900/s1869_longer_contiguous_segments_of_ones_than_zeros/Solution.kt)| Easy | String | 118 | 100.00
1953+
| 1866 |[Number of Ways to Rearrange Sticks With K Sticks Visible](src/main/kotlin/g1801_1900/s1866_number_of_ways_to_rearrange_sticks_with_k_sticks_visible/Solution.kt)| Hard | Dynamic_Programming, Math, Combinatorics | 188 | 100.00
1954+
| 1865 |[Finding Pairs With a Certain Sum](src/main/kotlin/g1801_1900/s1865_finding_pairs_with_a_certain_sum/FindSumPairs.kt)| Medium | Array, Hash_Table, Design | 1050 | 100.00
1955+
| 1864 |[Minimum Number of Swaps to Make the Binary String Alternating](src/main/kotlin/g1801_1900/s1864_minimum_number_of_swaps_to_make_the_binary_string_alternating/Solution.kt)| Medium | String, Greedy | 140 | 100.00
1956+
| 1863 |[Sum of All Subset XOR Totals](src/main/kotlin/g1801_1900/s1863_sum_of_all_subset_xor_totals/Solution.kt)| Easy | Array, Math, Bit_Manipulation, Backtracking, Combinatorics | 128 | 80.00
1957+
| 1862 |[Sum of Floored Pairs](src/main/kotlin/g1801_1900/s1862_sum_of_floored_pairs/Solution.kt)| Hard | Array, Math, Binary_Search, Prefix_Sum | 710 | 100.00
1958+
| 1861 |[Rotating the Box](src/main/kotlin/g1801_1900/s1861_rotating_the_box/Solution.kt)| Medium | Array, Matrix, Two_Pointers | 882 | 60.00
1959+
| 1860 |[Incremental Memory Leak](src/main/kotlin/g1801_1900/s1860_incremental_memory_leak/Solution.kt)| Medium | Simulation | 161 | 100.00
1960+
| 1859 |[Sorting the Sentence](src/main/kotlin/g1801_1900/s1859_sorting_the_sentence/Solution.kt)| Easy | String, Sorting | 155 | 89.29
1961+
| 1857 |[Largest Color Value in a Directed Graph](src/main/kotlin/g1801_1900/s1857_largest_color_value_in_a_directed_graph/Solution.kt)| Hard | Hash_Table, Dynamic_Programming, Graph, Counting, Memoization, Topological_Sort | 1308 | 20.00
1962+
| 1856 |[Maximum Subarray Min-Product](src/main/kotlin/g1801_1900/s1856_maximum_subarray_min_product/Solution.kt)| Medium | Array, Stack, Prefix_Sum, Monotonic_Stack | 517 | 66.67
1963+
| 1855 |[Maximum Distance Between a Pair of Values](src/main/kotlin/g1801_1900/s1855_maximum_distance_between_a_pair_of_values/Solution.kt)| Medium | Array, Greedy, Binary_Search, Two_Pointers, Binary_Search_I_Day_11 | 541 | 14.29
1964+
| 1854 |[Maximum Population Year](src/main/kotlin/g1801_1900/s1854_maximum_population_year/Solution.kt)| Easy | Array, Counting | 148 | 90.00
1965+
| 1851 |[Minimum Interval to Include Each Query](src/main/kotlin/g1801_1900/s1851_minimum_interval_to_include_each_query/Solution.kt)| Hard | Array, Sorting, Binary_Search, Heap_Priority_Queue, Line_Sweep | 1612 | 87.50
19191966
| 1850 |[Minimum Adjacent Swaps to Reach the Kth Smallest Number](src/main/kotlin/g1801_1900/s1850_minimum_adjacent_swaps_to_reach_the_kth_smallest_number/Solution.kt)| Medium | String, Greedy, Two_Pointers | 193 | 100.00
19201967
| 1849 |[Splitting a String Into Descending Consecutive Values](src/main/kotlin/g1801_1900/s1849_splitting_a_string_into_descending_consecutive_values/Solution.kt)| Medium | String, Backtracking | 136 | 100.00
19211968
| 1848 |[Minimum Distance to the Target Element](src/main/kotlin/g1801_1900/s1848_minimum_distance_to_the_target_element/Solution.kt)| Easy | Array | 172 | 80.00

src/main/kotlin/g1801_1900/s1845_seat_reservation_manager/SeatManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package g1801_1900.s1845_seat_reservation_manager
66
import java.util.PriorityQueue
77
import java.util.Queue
88

9+
@Suppress("UNUSED_PARAMETER")
910
class SeatManager(n: Int) {
1011
private val seats: Queue<Int>
1112
private var smallest: Int
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package g1801_1900.s1851_minimum_interval_to_include_each_query
2+
3+
// #Hard #Array #Sorting #Binary_Search #Heap_Priority_Queue #Line_Sweep
4+
// #2023_06_22_Time_1612_ms_(87.50%)_Space_129.5_MB_(75.00%)
5+
6+
import java.util.Arrays
7+
import java.util.PriorityQueue
8+
9+
class Solution {
10+
fun minInterval(intervals: Array<IntArray>, queries: IntArray): IntArray {
11+
val numQuery = queries.size
12+
val queriesWithIndex = Array(numQuery) { IntArray(2) }
13+
for (i in 0 until numQuery) {
14+
queriesWithIndex[i] = intArrayOf(queries[i], i)
15+
}
16+
Arrays.sort(intervals, { a: IntArray, b: IntArray -> a[0].compareTo(b[0]) })
17+
Arrays.sort(queriesWithIndex, { a: IntArray, b: IntArray -> a[0].compareTo(b[0]) })
18+
val minHeap = PriorityQueue({ a: IntArray, b: IntArray -> (a[1] - a[0]).compareTo(b[1] - b[0]) })
19+
val result = IntArray(numQuery)
20+
var j = 0
21+
for (i in queries.indices) {
22+
val queryVal = queriesWithIndex[i][0]
23+
val queryIndex = queriesWithIndex[i][1]
24+
while (j < intervals.size && intervals[j][0] <= queryVal) {
25+
minHeap.add(intervals[j])
26+
j++
27+
}
28+
while (minHeap.isNotEmpty() && minHeap.peek()[1] < queryVal) {
29+
minHeap.remove()
30+
}
31+
result[queryIndex] = if (minHeap.isEmpty()) -1 else minHeap.peek()[1] - minHeap.peek()[0] + 1
32+
}
33+
return result
34+
}
35+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
1851\. Minimum Interval to Include Each Query
2+
3+
Hard
4+
5+
You are given a 2D integer array `intervals`, where <code>intervals[i] = [left<sub>i</sub>, right<sub>i</sub>]</code> describes the <code>i<sup>th</sup></code> interval starting at <code>left<sub>i</sub></code> and ending at <code>right<sub>i</sub></code> **(inclusive)**. The **size** of an interval is defined as the number of integers it contains, or more formally <code>right<sub>i</sub> - left<sub>i</sub> + 1</code>.
6+
7+
You are also given an integer array `queries`. The answer to the <code>j<sup>th</sup></code> query is the **size of the smallest interval** `i` such that <code>left<sub>i</sub> <= queries[j] <= right<sub>i</sub></code>. If no such interval exists, the answer is `-1`.
8+
9+
Return _an array containing the answers to the queries_.
10+
11+
**Example 1:**
12+
13+
**Input:** intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]
14+
15+
**Output:** [3,3,1,4]
16+
17+
**Explanation:** The queries are processed as follows:
18+
19+
- Query = 2: The interval [2,4] is the smallest interval containing 2. The answer is 4 - 2 + 1 = 3.
20+
21+
- Query = 3: The interval [2,4] is the smallest interval containing 3. The answer is 4 - 2 + 1 = 3.
22+
23+
- Query = 4: The interval [4,4] is the smallest interval containing 4. The answer is 4 - 4 + 1 = 1.
24+
25+
- Query = 5: The interval [3,6] is the smallest interval containing 5. The answer is 6 - 3 + 1 = 4.
26+
27+
**Example 2:**
28+
29+
**Input:** intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]
30+
31+
**Output:** [2,-1,4,6]
32+
33+
**Explanation:** The queries are processed as follows:
34+
35+
- Query = 2: The interval [2,3] is the smallest interval containing 2. The answer is 3 - 2 + 1 = 2.
36+
37+
- Query = 19: None of the intervals contain 19. The answer is -1.
38+
39+
- Query = 5: The interval [2,5] is the smallest interval containing 5. The answer is 5 - 2 + 1 = 4.
40+
41+
- Query = 22: The interval [20,25] is the smallest interval containing 22. The answer is 25 - 20 + 1 = 6.
42+
43+
**Constraints:**
44+
45+
* <code>1 <= intervals.length <= 10<sup>5</sup></code>
46+
* <code>1 <= queries.length <= 10<sup>5</sup></code>
47+
* `intervals[i].length == 2`
48+
* <code>1 <= left<sub>i</sub> <= right<sub>i</sub> <= 10<sup>7</sup></code>
49+
* <code>1 <= queries[j] <= 10<sup>7</sup></code>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package g1801_1900.s1854_maximum_population_year
2+
3+
// #Easy #Array #Counting #2023_06_22_Time_148_ms_(90.00%)_Space_34.5_MB_(90.00%)
4+
5+
class Solution {
6+
fun maximumPopulation(logs: Array<IntArray>): Int {
7+
val arr = IntArray(101)
8+
for (log in logs) {
9+
arr[log[0] - 1950]++
10+
arr[log[1] - 1950]--
11+
}
12+
for (i in 1..100) {
13+
arr[i] += arr[i - 1]
14+
}
15+
var maxyear = 1950
16+
var max = 0
17+
for (i in 0..100) {
18+
if (arr[i] > max) {
19+
max = arr[i]
20+
maxyear = i + 1950
21+
}
22+
}
23+
return maxyear
24+
}
25+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
1854\. Maximum Population Year
2+
3+
Easy
4+
5+
You are given a 2D integer array `logs` where each <code>logs[i] = [birth<sub>i</sub>, death<sub>i</sub>]</code> indicates the birth and death years of the <code>i<sup>th</sup></code> person.
6+
7+
The **population** of some year `x` is the number of people alive during that year. The <code>i<sup>th</sup></code> person is counted in year `x`'s population if `x` is in the **inclusive** range <code>[birth<sub>i</sub>, death<sub>i</sub> - 1]</code>. Note that the person is **not** counted in the year that they die.
8+
9+
Return _the **earliest** year with the **maximum population**_.
10+
11+
**Example 1:**
12+
13+
**Input:** logs = [[1993,1999],[2000,2010]]
14+
15+
**Output:** 1993
16+
17+
**Explanation:** The maximum population is 1, and 1993 is the earliest year with this population.
18+
19+
**Example 2:**
20+
21+
**Input:** logs = [[1950,1961],[1960,1971],[1970,1981]]
22+
23+
**Output:** 1960
24+
25+
**Explanation:**
26+
27+
The maximum population is 2, and it had happened in years 1960 and 1970.
28+
29+
The earlier year between them is 1960.
30+
31+
**Constraints:**
32+
33+
* `1 <= logs.length <= 100`
34+
* <code>1950 <= birth<sub>i</sub> < death<sub>i</sub> <= 2050</code>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package g1801_1900.s1855_maximum_distance_between_a_pair_of_values
2+
3+
// #Medium #Array #Greedy #Binary_Search #Two_Pointers #Binary_Search_I_Day_11
4+
// #2023_06_22_Time_541_ms_(14.29%)_Space_54.8_MB_(85.71%)
5+
6+
class Solution {
7+
fun maxDistance(nums1: IntArray, nums2: IntArray): Int {
8+
val n = nums1.size
9+
val m = nums2.size
10+
var po1 = 0
11+
var po2 = 0
12+
var res = 0
13+
while (po1 < n && po2 < m) {
14+
if (nums1[po1] > nums2[po2]) {
15+
po1++
16+
} else {
17+
if (po2 != po1) {
18+
res = Math.max(res, po2 - po1)
19+
}
20+
po2++
21+
}
22+
}
23+
return res
24+
}
25+
}

0 commit comments

Comments
 (0)