Skip to content

Commit ec9dcbd

Browse files
committed
Added tasks 3446-3449
1 parent 0e33325 commit ec9dcbd

File tree

9 files changed

+674
-244
lines changed
  • src/main/kotlin
    • g1001_1100/s1044_longest_duplicate_substring
    • g2501_2600/s2551_put_marbles_in_bags
    • g3201_3300/s3245_alternating_groups_iii
    • g3301_3400/s3367_maximize_sum_of_weights_after_edge_removals
    • g3401_3500
      • s3446_sort_matrix_by_diagonals
      • s3447_assign_elements_to_groups_with_constraints
      • s3448_count_substrings_divisible_by_last_digit
      • s3449_maximize_the_minimum_game_score

9 files changed

+674
-244
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,10 @@
20842084

20852085
| # | Title | Difficulty | Tag | Time, ms | Time, %
20862086
|------|----------------|-------------|-------------|----------|--------
2087+
| 3449 |[Maximize the Minimum Game Score](src/main/kotlin/g3401_3500/s3449_maximize_the_minimum_game_score)| Hard | Array, Greedy, Binary_Search | 123 | 100.00
2088+
| 3448 |[Count Substrings Divisible By Last Digit](src/main/kotlin/g3401_3500/s3448_count_substrings_divisible_by_last_digit)| Hard | String, Dynamic_Programming | 28 | 77.78
2089+
| 3447 |[Assign Elements to Groups with Constraints](src/main/kotlin/g3401_3500/s3447_assign_elements_to_groups_with_constraints)| Medium | Array, Hash_Table | 24 | 100.00
2090+
| 3446 |[Sort Matrix by Diagonals](src/main/kotlin/g3401_3500/s3446_sort_matrix_by_diagonals)| Medium | Array, Sorting, Matrix | 12 | 93.75
20872091
| 3445 |[Maximum Difference Between Even and Odd Frequency II](src/main/kotlin/g3401_3500/s3445_maximum_difference_between_even_and_odd_frequency_ii)| Hard | String, Prefix_Sum, Sliding_Window, Enumeration | 84 | 83.33
20882092
| 3444 |[Minimum Increments for Target Multiples in an Array](src/main/kotlin/g3401_3500/s3444_minimum_increments_for_target_multiples_in_an_array)| Hard | Array, Dynamic_Programming, Math, Bit_Manipulation, Bitmask, Number_Theory | 34 | 100.00
20892093
| 3443 |[Maximum Manhattan Distance After K Changes](src/main/kotlin/g3401_3500/s3443_maximum_manhattan_distance_after_k_changes)| Medium | String, Hash_Table, Math, Counting | 52 | 100.00
@@ -2243,7 +2247,7 @@
22432247
| 3250 |[Find the Count of Monotonic Pairs I](src/main/kotlin/g3201_3300/s3250_find_the_count_of_monotonic_pairs_i)| Hard | Array, Dynamic_Programming, Math, Prefix_Sum, Combinatorics | 241 | 100.00
22442248
| 3249 |[Count the Number of Good Nodes](src/main/kotlin/g3201_3300/s3249_count_the_number_of_good_nodes)| Medium | Depth_First_Search, Tree | 1190 | 100.00
22452249
| 3248 |[Snake in Matrix](src/main/kotlin/g3201_3300/s3248_snake_in_matrix)| Easy | Array, String, Simulation | 174 | 90.91
2246-
| 3245 |[Alternating Groups III](src/main/kotlin/g3201_3300/s3245_alternating_groups_iii)| Hard | Array, Binary_Indexed_Tree | 1072 | 100.00
2250+
| 3245 |[Alternating Groups III](src/main/kotlin/g3201_3300/s3245_alternating_groups_iii)| Hard | Array, Binary_Indexed_Tree | 188 | 100.00
22472251
| 3244 |[Shortest Distance After Road Addition Queries II](src/main/kotlin/g3201_3300/s3244_shortest_distance_after_road_addition_queries_ii)| Hard | Array, Greedy, Graph, Ordered_Set | 794 | 92.31
22482252
| 3243 |[Shortest Distance After Road Addition Queries I](src/main/kotlin/g3201_3300/s3243_shortest_distance_after_road_addition_queries_i)| Medium | Array, Breadth_First_Search, Graph | 313 | 97.06
22492253
| 3242 |[Design Neighbor Sum Service](src/main/kotlin/g3201_3300/s3242_design_neighbor_sum_service)| Easy | Array, Hash_Table, Matrix, Design, Simulation | 333 | 75.00

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Return **any** duplicated substring that has the longest possible length. If `s`
3232
class Solution {
3333
private lateinit var hsh: LongArray
3434
private lateinit var pw: LongArray
35-
private val cnt: Array<MutableList<Int>?> = arrayOfNulls(26)
35+
private val cnt: Array<MutableList<Int>> = Array(26) { ArrayList() }
3636

3737
fun longestDupSubstring(s: String): String {
3838
val n = s.length
@@ -46,17 +46,17 @@ class Solution {
4646
for (j in 1..n) {
4747
hsh[j] = (hsh[j - 1] * base + s[j - 1].code.toLong()) % MOD
4848
pw[j] = pw[j - 1] * base % MOD
49-
cnt[s[j - 1].code - 'a'.code]!!.add(j - 1)
49+
cnt[s[j - 1].code - 'a'.code].add(j - 1)
5050
}
5151
var ans = ""
5252
for (i in 0..25) {
53-
if (cnt[i]!!.isEmpty()) {
53+
if (cnt[i].isEmpty()) {
5454
continue
5555
}
56-
val idx: MutableList<Int>? = cnt[i]
57-
var set: MutableSet<Long?>
56+
val idx: MutableList<Int> = cnt[i]
57+
var set: MutableSet<Long>
5858
var lo = 1
59-
var hi = n - idx!![0]
59+
var hi = n - idx[0]
6060
while (lo <= hi) {
6161
val len = (lo + hi) / 2
6262
set = HashSet()

src/main/kotlin/g2501_2600/s2551_put_marbles_in_bags/readme.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,27 @@ import java.util.PriorityQueue
5555

5656
class Solution {
5757
fun putMarbles(weights: IntArray, k: Int): Long {
58-
// Map<Pair<Integer, Integer>, long[]> memo = new HashMap<>();
59-
// long[] res = dfs(weights, 0, k, memo);
60-
// return res[1] - res[0];
61-
if (k == 1 || k == weights.size) return 0
58+
if (k == 1 || k == weights.size) {
59+
return 0
60+
}
6261
val min = PriorityQueue<Long>()
63-
val max = PriorityQueue { a: Long?, b: Long? ->
64-
java.lang.Long.compare(
65-
b!!,
66-
a!!,
67-
)
62+
val max = PriorityQueue { a: Long, b: Long ->
63+
b.compareTo(a)
6864
}
6965
for (i in 0 until weights.size - 1) {
7066
val sum = weights[i].toLong() + weights[i + 1]
7167
min.offer(sum)
7268
max.offer(sum)
73-
if (min.size == k) min.poll()
74-
if (max.size == k) max.poll()
69+
if (min.size == k) {
70+
min.poll()
71+
}
72+
if (max.size == k) {
73+
max.poll()
74+
}
7575
}
7676
var res: Long = 0
7777
while (max.isNotEmpty()) {
78-
res += min.poll() - max.poll()!!
78+
res += min.poll() - max.poll()
7979
}
8080
return res
8181
}

0 commit comments

Comments
 (0)