Skip to content

Commit fffd59c

Browse files
authored
Added tasks 3070-3108
1 parent 965c4b2 commit fffd59c

File tree

42 files changed

+2751
-29
lines changed
  • src/main/kotlin
    • g1201_1300/s1275_find_winner_on_a_tic_tac_toe_game
    • g1501_1600/s1579_remove_max_number_of_edges_to_keep_graph_fully_traversable
    • g1601_1700
      • s1632_rank_transform_of_a_matrix
      • s1665_minimum_initial_energy_to_finish_tasks
      • s1691_maximum_height_by_stacking_cuboids
      • s1697_checking_existence_of_edge_length_limited_paths
    • g1701_1800
      • s1710_maximum_units_on_a_truck
      • s1751_maximum_number_of_events_that_can_be_attended_ii
    • g1801_1900
    • g3001_3100
      • s3070_count_submatrices_with_top_left_element_and_sum_less_than_k
      • s3071_minimum_operations_to_write_the_letter_y_on_a_grid
      • s3072_distribute_elements_into_two_arrays_ii
      • s3074_apple_redistribution_into_boxes
      • s3075_maximize_happiness_of_selected_children
      • s3076_shortest_uncommon_substring_in_an_array
      • s3077_maximum_strength_of_k_disjoint_subarrays
      • s3079_find_the_sum_of_encrypted_integers
      • s3080_mark_elements_on_array_by_performing_queries
      • s3081_replace_question_marks_in_string_to_minimize_its_value
      • s3082_find_the_sum_of_the_power_of_all_subsequences
      • s3083_existence_of_a_substring_in_a_string_and_its_reverse
      • s3084_count_substrings_starting_and_ending_with_given_character
      • s3085_minimum_deletions_to_make_string_k_special
      • s3086_minimum_moves_to_pick_k_ones
      • s3090_maximum_length_substring_with_two_occurrences
      • s3091_apply_operations_to_make_sum_of_array_greater_than_or_equal_to_k
      • s3092_most_frequent_ids
      • s3093_longest_common_suffix_queries
      • s3095_shortest_subarray_with_or_at_least_k_i
      • s3096_minimum_levels_to_gain_more_points
      • s3097_shortest_subarray_with_or_at_least_k_ii
      • s3098_find_the_sum_of_subsequence_powers
      • s3099_harshad_number
      • s3100_water_bottles_ii
    • g3101_3200
      • s3101_count_alternating_subarrays
      • s3102_minimize_manhattan_distances
      • s3105_longest_strictly_increasing_or_strictly_decreasing_subarray
      • s3106_lexicographically_smallest_string_after_operations_with_constraint
      • s3107_minimum_operations_to_make_median_of_array_equal_to_k
      • s3108_minimum_cost_walk_in_weighted_graph

Some content is hidden

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

42 files changed

+2751
-29
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,37 @@
18161816

18171817
| # | Title | Difficulty | Tag | Time, ms | Time, %
18181818
|------|----------------|-------------|-------------|----------|--------
1819+
| 3108 |[Minimum Cost Walk in Weighted Graph](src/main/kotlin/g3101_3200/s3108_minimum_cost_walk_in_weighted_graph)| Hard | Array, Bit_Manipulation, Graph, Union_Find | 791 | 100.00
1820+
| 3107 |[Minimum Operations to Make Median of Array Equal to K](src/main/kotlin/g3101_3200/s3107_minimum_operations_to_make_median_of_array_equal_to_k)| Medium | Array, Sorting, Greedy | 554 | 100.00
1821+
| 3106 |[Lexicographically Smallest String After Operations With Constraint](src/main/kotlin/g3101_3200/s3106_lexicographically_smallest_string_after_operations_with_constraint)| Medium | String, Greedy | 162 | 74.19
1822+
| 3105 |[Longest Strictly Increasing or Strictly Decreasing Subarray](src/main/kotlin/g3101_3200/s3105_longest_strictly_increasing_or_strictly_decreasing_subarray)| Easy | Array | 159 | 94.00
1823+
| 3102 |[Minimize Manhattan Distances](src/main/kotlin/g3101_3200/s3102_minimize_manhattan_distances)| Hard | Array, Math | 701 | 95.83
1824+
| 3101 |[Count Alternating Subarrays](src/main/kotlin/g3101_3200/s3101_count_alternating_subarrays)| Medium | Array, Math | 499 | 97.78
1825+
| 3100 |[Water Bottles II](src/main/kotlin/g3001_3100/s3100_water_bottles_ii)| Medium | Math, Simulation | 137 | 70.49
1826+
| 3099 |[Harshad Number](src/main/kotlin/g3001_3100/s3099_harshad_number)| Easy | Math | 119 | 82.67
1827+
| 3098 |[Find the Sum of Subsequence Powers](src/main/kotlin/g3001_3100/s3098_find_the_sum_of_subsequence_powers)| Hard | Array, Dynamic_Programming, Sorting | 294 | 77.78
1828+
| 3097 |[Shortest Subarray With OR at Least K II](src/main/kotlin/g3001_3100/s3097_shortest_subarray_with_or_at_least_k_ii)| Medium | Array, Bit_Manipulation, Sliding_Window | 489 | 93.33
1829+
| 3096 |[Minimum Levels to Gain More Points](src/main/kotlin/g3001_3100/s3096_minimum_levels_to_gain_more_points)| Medium | Array, Prefix_Sum | 850 | 100.00
1830+
| 3095 |[Shortest Subarray With OR at Least K I](src/main/kotlin/g3001_3100/s3095_shortest_subarray_with_or_at_least_k_i)| Easy | Array, Bit_Manipulation, Sliding_Window | 161 | 95.65
1831+
| 3093 |[Longest Common Suffix Queries](src/main/kotlin/g3001_3100/s3093_longest_common_suffix_queries)| Hard | Array, String, Trie | 860 | 89.29
1832+
| 3092 |[Most Frequent IDs](src/main/kotlin/g3001_3100/s3092_most_frequent_ids)| Medium | Array, Hash_Table, Heap_Priority_Queue, Ordered_Set | 758 | 100.00
1833+
| 3091 |[Apply Operations to Make Sum of Array Greater Than or Equal to k](src/main/kotlin/g3001_3100/s3091_apply_operations_to_make_sum_of_array_greater_than_or_equal_to_k)| Medium | Math, Greedy, Enumeration | 134 | 73.21
1834+
| 3090 |[Maximum Length Substring With Two Occurrences](src/main/kotlin/g3001_3100/s3090_maximum_length_substring_with_two_occurrences)| Easy | String, Hash_Table, Sliding_Window | 157 | 90.24
1835+
| 3086 |[Minimum Moves to Pick K Ones](src/main/kotlin/g3001_3100/s3086_minimum_moves_to_pick_k_ones)| Hard | Array, Greedy, Prefix_Sum, Sliding_Window | 368 | 100.00
1836+
| 3085 |[Minimum Deletions to Make String K-Special](src/main/kotlin/g3001_3100/s3085_minimum_deletions_to_make_string_k_special)| Medium | String, Hash_Table, Sorting, Greedy, Counting | 221 | 93.33
1837+
| 3084 |[Count Substrings Starting and Ending with Given Character](src/main/kotlin/g3001_3100/s3084_count_substrings_starting_and_ending_with_given_character)| Medium | String, Math, Counting | 177 | 98.55
1838+
| 3083 |[Existence of a Substring in a String and Its Reverse](src/main/kotlin/g3001_3100/s3083_existence_of_a_substring_in_a_string_and_its_reverse)| Easy | String, Hash_Table | 168 | 79.49
1839+
| 3082 |[Find the Sum of the Power of All Subsequences](src/main/kotlin/g3001_3100/s3082_find_the_sum_of_the_power_of_all_subsequences)| Hard | Array, Dynamic_Programming | 176 | 90.00
1840+
| 3081 |[Replace Question Marks in String to Minimize Its Value](src/main/kotlin/g3001_3100/s3081_replace_question_marks_in_string_to_minimize_its_value)| Medium | String, Hash_Table, Sorting, Greedy, Heap_Priority_Queue, Counting | 249 | 100.00
1841+
| 3080 |[Mark Elements on Array by Performing Queries](src/main/kotlin/g3001_3100/s3080_mark_elements_on_array_by_performing_queries)| Medium | Array, Hash_Table, Sorting, Heap_Priority_Queue, Simulation | 937 | 97.78
1842+
| 3079 |[Find the Sum of Encrypted Integers](src/main/kotlin/g3001_3100/s3079_find_the_sum_of_encrypted_integers)| Easy | Array, Math | 172 | 80.60
1843+
| 3077 |[Maximum Strength of K Disjoint Subarrays](src/main/kotlin/g3001_3100/s3077_maximum_strength_of_k_disjoint_subarrays)| Hard | Array, Dynamic_Programming, Prefix_Sum | 351 | 75.00
1844+
| 3076 |[Shortest Uncommon Substring in an Array](src/main/kotlin/g3001_3100/s3076_shortest_uncommon_substring_in_an_array)| Medium | Array, String, Hash_Table, Trie | 256 | 100.00
1845+
| 3075 |[Maximize Happiness of Selected Children](src/main/kotlin/g3001_3100/s3075_maximize_happiness_of_selected_children)| Medium | Array, Sorting, Greedy | 608 | 93.24
1846+
| 3074 |[Apple Redistribution into Boxes](src/main/kotlin/g3001_3100/s3074_apple_redistribution_into_boxes)| Easy | Array, Sorting, Greedy | 168 | 97.37
1847+
| 3072 |[Distribute Elements Into Two Arrays II](src/main/kotlin/g3001_3100/s3072_distribute_elements_into_two_arrays_ii)| Hard | Array, Simulation, Segment_Tree, Binary_Indexed_Tree | 890 | 100.00
1848+
| 3071 |[Minimum Operations to Write the Letter Y on a Grid](src/main/kotlin/g3001_3100/s3071_minimum_operations_to_write_the_letter_y_on_a_grid)| Medium | Array, Hash_Table, Matrix, Counting | 268 | 91.11
1849+
| 3070 |[Count Submatrices with Top-Left Element and Sum Less Than k](src/main/kotlin/g3001_3100/s3070_count_submatrices_with_top_left_element_and_sum_less_than_k)| Medium | Array, Matrix, Prefix_Sum | 773 | 85.71
18191850
| 3069 |[Distribute Elements Into Two Arrays I](src/main/kotlin/g3001_3100/s3069_distribute_elements_into_two_arrays_i)| Easy | Array, Simulation | 207 | 96.92
18201851
| 3068 |[Find the Maximum Sum of Node Values](src/main/kotlin/g3001_3100/s3068_find_the_maximum_sum_of_node_values)| Hard | Array, Dynamic_Programming, Sorting, Greedy, Tree, Bit_Manipulation | 531 | 66.67
18211852
| 3067 |[Count Pairs of Connectable Servers in a Weighted Tree Network](src/main/kotlin/g3001_3100/s3067_count_pairs_of_connectable_servers_in_a_weighted_tree_network)| Medium | Array, Depth_First_Search, Tree | 578 | 83.33

src/main/kotlin/g1201_1300/s1275_find_winner_on_a_tic_tac_toe_game/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ class Solution {
111111
}
112112
}
113113
}
114-
```
114+
```

src/main/kotlin/g1501_1600/s1579_remove_max_number_of_edges_to_keep_graph_fully_traversable/readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ Return _the maximum number of edges you can remove, or return_ `-1` _if it's imp
5757
## Solution
5858

5959
```kotlin
60-
import java.util.Arrays
61-
6260
class Solution {
6361
fun maxNumEdgesToRemove(n: Int, edges: Array<IntArray>): Int {
64-
Arrays.sort(edges) { a: IntArray, b: IntArray -> b[0] - a[0] }
62+
edges.sortWith { a: IntArray, b: IntArray -> b[0] - a[0] }
6563
val alice = IntArray(n + 1)
6664
val rankAlice = IntArray(n + 1)
6765
val bob = IntArray(n + 1)

src/main/kotlin/g1601_1700/s1632_rank_transform_of_a_matrix/readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ The rank of matrix[1][1] is 3 because matrix[1][1] > matrix[0][1], matrix[1][1]
6262
## Solution
6363

6464
```kotlin
65-
import java.util.Arrays
66-
6765
class Solution {
6866
fun matrixRankTransform(matrix: Array<IntArray>): Array<IntArray> {
6967
val rowCount = matrix.size
@@ -108,7 +106,7 @@ class Solution {
108106
} else {
109107
val rowCount = matrix.size
110108
val ufind = IntArray(rowCount + matrix[0].size)
111-
Arrays.fill(ufind, -1)
109+
ufind.fill(-1)
112110
for (nIdx in startIdx until endIdx) {
113111
val r = nums[nIdx].toInt() shr 16 and 0xFFFF
114112
val c = nums[nIdx].toInt() and 0xFFFF

src/main/kotlin/g1601_1700/s1665_minimum_initial_energy_to_finish_tasks/readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ Starting with 27 energy, we finish the tasks in the following order:
8484
## Solution
8585

8686
```kotlin
87-
import java.util.Arrays
88-
8987
class Solution {
9088
fun minimumEffort(tasks: Array<IntArray>): Int {
91-
Arrays.sort(tasks) { a: IntArray, b: IntArray -> a[1] - a[0] - b[1] + b[0] }
89+
tasks.sortWith { a: IntArray, b: IntArray -> a[1] - a[0] - b[1] + b[0] }
9290
var prev = 0
9391
for (item in tasks) {
9492
prev = Math.max(prev + item[0], item[1])

src/main/kotlin/g1601_1700/s1691_maximum_height_by_stacking_cuboids/readme.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,13 @@ The maximum height of stacked cuboids is 6 \* 17 = 102.
6464
## Solution
6565

6666
```kotlin
67-
import java.util.Arrays
68-
6967
class Solution {
7068
fun maxHeight(cuboids: Array<IntArray>): Int {
7169
for (a in cuboids) {
7270
a.sort()
7371
}
74-
Arrays.sort(
75-
cuboids
76-
) { a: IntArray, b: IntArray ->
72+
73+
cuboids.sortWith sort@{ a: IntArray, b: IntArray ->
7774
if (a[0] != b[0]) {
7875
return@sort a[0] - b[0]
7976
} else if (a[1] != b[1]) {

src/main/kotlin/g1601_1700/s1697_checking_existence_of_edge_length_limited_paths/readme.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ For the second query, there is a path (0 -> 1 -> 2) of two edges with distances
4848
## Solution
4949

5050
```kotlin
51-
import java.util.Arrays
52-
5351
class Solution {
5452
private class Dsu(n: Int) {
5553
private val parent: IntArray
@@ -77,12 +75,12 @@ class Solution {
7775
}
7876

7977
fun distanceLimitedPathsExist(n: Int, edgeList: Array<IntArray>, queries: Array<IntArray>): BooleanArray {
80-
Arrays.sort(edgeList) { o1: IntArray, o2: IntArray -> Integer.compare(o1[2], o2[2]) }
78+
edgeList.sortWith { o1: IntArray, o2: IntArray -> Integer.compare(o1[2], o2[2]) }
8179
val data = Array(queries.size) { IntArray(4) }
8280
for (i in queries.indices) {
8381
data[i] = intArrayOf(queries[i][0], queries[i][1], queries[i][2], i)
8482
}
85-
Arrays.sort(data) { o1: IntArray, o2: IntArray -> Integer.compare(o1[2], o2[2]) }
83+
data.sortWith { o1: IntArray, o2: IntArray -> Integer.compare(o1[2], o2[2]) }
8684
val d = Dsu(n)
8785
var j = 0
8886
val ans = BooleanArray(queries.size)

src/main/kotlin/g1701_1800/s1710_maximum_units_on_a_truck/readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ Return _the **maximum** total number of **units** that can be put on the truck._
4343
## Solution
4444

4545
```kotlin
46-
import java.util.Arrays
47-
4846
@Suppress("NAME_SHADOWING")
4947
class Solution {
5048
fun maximumUnits(boxTypes: Array<IntArray>, truckSize: Int): Int {
5149
var truckSize = truckSize
52-
Arrays.sort(boxTypes) { b1: IntArray, b2: IntArray -> Integer.compare(b2[1], b1[1]) }
50+
boxTypes.sortWith { b1: IntArray, b2: IntArray -> Integer.compare(b2[1], b1[1]) }
5351
var maxUnits = 0
5452
var i = 0
5553
while (truckSize > 0 && i < boxTypes.size) {

src/main/kotlin/g1701_1800/s1751_maximum_number_of_events_that_can_be_attended_ii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Solution {
6565
}
6666
}
6767
val n = events.size
68-
Arrays.sort(events, { a: IntArray, b: IntArray -> a[0].compareTo(b[0]) })
68+
events.sortWith { a: IntArray, b: IntArray -> a[0].compareTo(b[0]) }
6969
val memo = Array(n) { IntArray(k + 1) }
7070
return dfs(events, 0, k, memo)
7171
}

src/main/kotlin/g1801_1900/s1847_closest_room/readme.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Query = [2,5]: Room number 3 is the only room with a size of at least 5. The ans
5656
## Solution
5757

5858
```kotlin
59-
import java.util.Arrays
6059
import java.util.TreeSet
6160

6261
class Solution {
@@ -66,8 +65,8 @@ class Solution {
6665
for (i in 0 until numQuery) {
6766
queries[i] = intArrayOf(queries[i][0], queries[i][1], i)
6867
}
69-
Arrays.sort(rooms) { a: IntArray, b: IntArray -> if (a[1] != b[1]) a[1] - b[1] else a[0] - b[0] }
70-
Arrays.sort(queries) { a: IntArray, b: IntArray -> if (a[1] != b[1]) a[1] - b[1] else a[0] - b[0] }
68+
rooms.sortWith { a: IntArray, b: IntArray -> if (a[1] != b[1]) a[1] - b[1] else a[0] - b[0] }
69+
queries.sortWith { a: IntArray, b: IntArray -> if (a[1] != b[1]) a[1] - b[1] else a[0] - b[0] }
7170
val roomIds = TreeSet<Int>()
7271
val result = IntArray(numQuery)
7372
var j = numRoom - 1

0 commit comments

Comments
 (0)