Skip to content

Commit 3bd424e

Browse files
committed
Added tasks 3512-3519
1 parent 902bbb9 commit 3bd424e

File tree

37 files changed

+1047
-218
lines changed
  • src/main/kotlin
    • g2801_2900
      • s2865_beautiful_towers_i
      • s2874_maximum_value_of_an_ordered_triplet_ii
      • s2896_apply_operations_to_make_two_strings_equal
    • g2901_3000
      • s2908_minimum_sum_of_mountain_triplets_i
      • s2909_minimum_sum_of_mountain_triplets_ii
      • s2911_minimum_changes_to_make_k_semi_palindromes
      • s2926_maximum_balanced_subsequence_sum
      • s2944_minimum_number_of_coins_for_fruits
      • s2954_count_the_number_of_infection_sequences
      • s2958_length_of_longest_subarray_with_at_most_k_frequency
    • g3001_3100
      • s3039_apply_operations_to_make_string_empty
      • s3074_apple_redistribution_into_boxes
      • s3076_shortest_uncommon_substring_in_an_array
      • s3086_minimum_moves_to_pick_k_ones
      • s3092_most_frequent_ids
    • g3101_3200
      • s3121_count_the_number_of_special_characters_ii
      • s3161_block_placement_queries
      • s3196_maximize_total_cost_of_alternating_subarrays
    • g3201_3300
      • s3207_maximum_points_after_enemy_battles
      • s3272_find_the_count_of_good_integers
    • g3301_3400
      • s3327_check_if_dfs_strings_are_palindromes
      • s3372_maximize_the_number_of_target_nodes_after_connecting_trees_i
      • s3394_check_if_grid_can_be_cut_into_sections
    • g3401_3500
      • s3411_maximum_subarray_with_equal_products
      • s3413_maximum_coins_from_k_consecutive_bags
      • s3459_length_of_longest_v_shaped_diagonal_segment
      • s3479_fruits_into_baskets_iii
    • g3501_3600
      • s3508_implement_router
      • s3512_minimum_operations_to_make_array_sum_divisible_by_k
      • s3513_number_of_unique_xor_triplets_i
      • s3514_number_of_unique_xor_triplets_ii
      • s3515_shortest_path_in_a_weighted_tree
      • s3516_find_closest_person
      • s3517_smallest_palindromic_rearrangement_i
      • s3518_smallest_palindromic_rearrangement_ii
      • s3519_count_numbers_with_non_decreasing_digits

37 files changed

+1047
-218
lines changed

README.md

+174-166
Large diffs are not rendered by default.

src/main/kotlin/g2801_2900/s2865_beautiful_towers_i/readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ class Solution {
7373
var ans = maxHeights[pickId].toLong()
7474
var min = maxHeights[pickId].toLong()
7575
for (i in pickId - 1 downTo 0) {
76-
min = min(min.toDouble(), maxHeights[i].toDouble()).toLong()
76+
min = min(min, maxHeights[i].toLong())
7777
ans += min
7878
}
7979
min = maxHeights[pickId].toLong()
8080
for (i in pickId + 1 until maxHeights.size) {
81-
min = min(min.toDouble(), maxHeights[i].toDouble()).toLong()
81+
min = min(min, maxHeights[i].toLong())
8282
ans += min
8383
}
8484
return ans
@@ -93,7 +93,7 @@ class Solution {
9393
maxHeights[i] >= maxHeights[i + 1]
9494
)
9595
) {
96-
ans = max(ans.toDouble(), `fun`(maxHeights, i).toDouble()).toLong()
96+
ans = max(ans, `fun`(maxHeights, i))
9797
}
9898
}
9999
return ans

src/main/kotlin/g2801_2900/s2874_maximum_value_of_an_ordered_triplet_ii/readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class Solution {
5151
var tempMax = nums[0]
5252
for (i in 1 until diff.size - 1) {
5353
diff[i] = tempMax - nums[i]
54-
tempMax = max(tempMax.toDouble(), nums[i].toDouble()).toInt()
54+
tempMax = max(tempMax, nums[i])
5555
}
5656
var max = Long.MIN_VALUE
5757
tempMax = nums[nums.size - 1]
5858
for (i in nums.size - 2 downTo 1) {
59-
max = max(max.toDouble(), (tempMax.toLong() * diff[i]).toDouble()).toLong()
60-
tempMax = max(tempMax.toDouble(), nums[i].toDouble()).toInt()
59+
max = max(max, tempMax.toLong() * diff[i])
60+
tempMax = max(tempMax, nums[i])
6161
}
62-
return max(max.toDouble(), 0.0).toLong()
62+
return max(max, 0)
6363
}
6464
}
6565
```

src/main/kotlin/g2801_2900/s2896_apply_operations_to_make_two_strings_equal/readme.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ class Solution {
6868
}
6969
val dp = IntArray(m)
7070
dp[0] = 0
71-
dp[1] = min(x.toDouble(), (diffs[1] - diffs[0]).toDouble()).toInt()
71+
dp[1] = min(x, diffs[1] - diffs[0])
7272
for (i in 2 until m) {
7373
if ((i and 1) == 1) {
74-
dp[i] = min((dp[i - 1] + x).toDouble(), (dp[i - 2] + diffs[i] - diffs[i - 1]).toDouble())
75-
.toInt()
74+
dp[i] = min(dp[i - 1] + x, dp[i - 2] + diffs[i] - diffs[i - 1])
7675
} else {
77-
dp[i] = min(dp[i - 1].toDouble(), (dp[i - 2] + diffs[i] - diffs[i - 1]).toDouble())
78-
.toInt()
76+
dp[i] = min(dp[i - 1], dp[i - 2] + diffs[i] - diffs[i - 1])
7977
}
8078
}
8179
return dp[m - 1]

src/main/kotlin/g2901_3000/s2908_minimum_sum_of_mountain_triplets_i/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Solution {
6767
for (k in j + 1 until nums.size) {
6868
if (nums[i] < nums[j] && nums[k] < nums[j]) {
6969
val min = nums[i] + nums[k] + nums[j]
70-
output = min(min.toDouble(), output.toDouble()).toInt()
70+
output = min(min, output)
7171
}
7272
}
7373
}

src/main/kotlin/g2901_3000/s2909_minimum_sum_of_mountain_triplets_ii/readme.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class Solution {
8484
var ans = Int.MAX_VALUE
8585
for (i in 0 until n) {
8686
if (leftSmallest[i] != -1 && rightSmallest[i] != -1) {
87-
ans = min(ans.toDouble(), (leftSmallest[i] + rightSmallest[i] + nums[i]).toDouble())
88-
.toInt()
87+
ans = min(ans, leftSmallest[i] + rightSmallest[i] + nums[i])
8988
}
9089
}
9190
if (ans == Int.MAX_VALUE) {

src/main/kotlin/g2901_3000/s2911_minimum_changes_to_make_k_semi_palindromes/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Solution {
7373
}
7474
var min = INF
7575
for (j in (k - 1) * 2 until (i - 1)) {
76-
min = min(min.toDouble(), (calc(j, k - 1) + change(j, i)).toDouble()).toInt()
76+
min = min(min, calc(j, k - 1) + change(j, i))
7777
}
7878
dp[i][k] = min
7979
return min

src/main/kotlin/g2901_3000/s2926_maximum_balanced_subsequence_sum/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class Solution {
130130
var index = index
131131
var result: Long = 0
132132
while (index > 0) {
133-
result = max(tree[index].toDouble(), result.toDouble()).toLong()
133+
result = max(tree[index], result)
134134
index -= lowbit(index)
135135
}
136136
return result

src/main/kotlin/g2901_3000/s2944_minimum_number_of_coins_for_fruits/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Solution {
7474
if (acquired + 1 < n) {
7575
var min = Int.MAX_VALUE
7676
for (j in acquired + 1 downTo i + 1) {
77-
min = min(min.toDouble(), dp[j].toDouble()).toInt()
77+
min = min(min, dp[j])
7878
}
7979
dp[i] = prices[i] + min
8080
} else {

src/main/kotlin/g2901_3000/s2954_count_the_number_of_infection_sequences/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Solution {
9292
var res: Long = 1
9393
for (i in 1 until sick.size) {
9494
val group = sick[i] - sick[i - 1] - 1
95-
res = res * modPow(2, max(0.0, (group - 1).toDouble()).toInt(), MOD) % MOD
95+
res = res * modPow(2, max(0, group - 1), MOD) % MOD
9696
res = res * binomCoeff(sick[i] - i, group) % MOD
9797
}
9898
return (res * binomCoeff(n - sick.size, n - sick[sick.size - 1] - 1) % MOD).toInt()

src/main/kotlin/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class Solution {
5656
var m1 = Int.MIN_VALUE
5757
var m2 = Int.MAX_VALUE
5858
for (num in nums) {
59-
m1 = max(m1.toDouble(), num.toDouble()).toInt()
60-
m2 = min(m2.toDouble(), num.toDouble()).toInt()
59+
m1 = max(m1, num)
60+
m2 = min(m2, num)
6161
}
6262
var max = 0
6363
val f = IntArray(m1 - m2 + 1)

src/main/kotlin/g3001_3100/s3039_apply_operations_to_make_string_empty/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Solution {
5757
val sb = StringBuilder()
5858
for (c in ar) {
5959
freq[c.code - 'a'.code]++
60-
max = max(freq[c.code - 'a'.code].toDouble(), max.toDouble()).toInt()
60+
max = max(freq[c.code - 'a'.code], max)
6161
}
6262
for (i in n - 1 downTo 0) {
6363
if (freq[ar[i].code - 'a'.code] == max) {

src/main/kotlin/g3001_3100/s3074_apple_redistribution_into_boxes/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Solution {
5252
var max = 0
5353
for (j in capacity) {
5454
count[j]++
55-
max = max(max.toDouble(), j.toDouble()).toInt()
55+
max = max(max, j)
5656
}
5757
for (i in max downTo 0) {
5858
if (count[i] >= 1) {

src/main/kotlin/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/readme.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ class Solution {
7272
val curLen = search(
7373
cs,
7474
i,
75-
min(m.toDouble(), (i + resultLen).toDouble())
76-
.toInt(),
75+
min(m, (i + resultLen)),
7776
k,
7877
)
7978
if (curLen != -1) {

src/main/kotlin/g3001_3100/s3086_minimum_moves_to_pick_k_ones/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class Solution {
103103
val area1 = (mid - l + 1).toLong() * median
104104
val area2 = (r - mid).toLong() * median
105105
val curRes = area1 - sum1 + sum2 - area2
106-
res = min(res.toDouble(), curRes.toDouble()).toLong()
106+
res = min(res, curRes)
107107
l++
108108
}
109109
res += 2L * maxChanges

src/main/kotlin/g3001_3100/s3092_most_frequent_ids/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Solution {
5555
var max = Int.MIN_VALUE
5656
val n = nums.size
5757
for (num in nums) {
58-
max = max(max.toDouble(), num.toDouble()).toInt()
58+
max = max(max, num)
5959
}
6060
val bins = LongArray(max + 1)
6161
var mostFrequentID = 0

src/main/kotlin/g3101_3200/s3121_count_the_number_of_special_characters_ii/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Solution {
5959
for (i in word.indices) {
6060
val a = word[i]
6161
if (a.code < 91) {
62-
capital[a.code - 65] = min(capital[a.code - 65].toDouble(), i.toDouble()).toInt()
62+
capital[a.code - 65] = min(capital[a.code - 65], i)
6363
} else {
6464
small[a.code - 97] = i
6565
}

src/main/kotlin/g3101_3200/s3161_block_placement_queries/readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Solution {
118118
right.parent[x] = next
119119
bit.update(next, next - pre)
120120
} else {
121-
val maxGap = max(bit.query(pre).toDouble(), (x - pre).toDouble()).toInt()
121+
val maxGap = max(bit.query(pre), x - pre)
122122
ans[index--] = maxGap >= q[2]
123123
}
124124
}
@@ -131,7 +131,7 @@ class Solution {
131131
fun update(i: Int, v: Int) {
132132
var i = i
133133
while (i < n) {
134-
tree[i] = max(tree[i].toDouble(), v.toDouble()).toInt()
134+
tree[i] = max(tree[i], v)
135135
i += i and -i
136136
}
137137
}
@@ -140,7 +140,7 @@ class Solution {
140140
var i = i
141141
var result = 0
142142
while (i > 0) {
143-
result = max(result.toDouble(), tree[i].toDouble()).toInt()
143+
result = max(result, tree[i])
144144
i = i and i - 1
145145
}
146146
return result

src/main/kotlin/g3101_3200/s3196_maximize_total_cost_of_alternating_subarrays/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Solution {
7777
var addResult = nums[0].toLong()
7878
var subResult = nums[0].toLong()
7979
for (i in 1 until n) {
80-
val tempAdd = (max(addResult.toDouble(), subResult.toDouble()) + nums[i]).toLong()
80+
val tempAdd = max(addResult, subResult) + nums[i]
8181
val tempSub = addResult - nums[i]
8282
addResult = tempAdd
8383
subResult = tempSub

src/main/kotlin/g3201_3300/s3207_maximum_points_after_enemy_battles/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Solution {
6464
val n = enemyEnergies.size
6565
var min = enemyEnergies[0]
6666
for (i in 1 until n) {
67-
min = min(min.toDouble(), enemyEnergies[i].toDouble()).toInt()
67+
min = min(min, enemyEnergies[i])
6868
}
6969
if (currentEnergy == 0 || currentEnergy < min) {
7070
return 0

src/main/kotlin/g3201_3300/s3272_find_the_count_of_good_integers/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Solution {
125125

126126
private fun allKPalindromes(n: Int, k: Int): List<String> {
127127
val ans = StringBuilder(n)
128-
ans.append("0".repeat(max(0.0, n.toDouble()).toInt()))
128+
ans.append("0".repeat(max(0, n)))
129129
val rem = IntArray(n)
130130
rem[0] = 1
131131
for (i in 1 until n) {

src/main/kotlin/g3301_3400/s3327_check_if_dfs_strings_are_palindromes/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Solution {
129129
for (i in 2..<m - 2) {
130130
var len = 0
131131
if (i < right) {
132-
len = min(lens[2 * center - i].toDouble(), (right - i).toDouble()).toInt()
132+
len = min(lens[2 * center - i], right - i)
133133
}
134134
while (t[i + len + 1] == t[i - len - 1]) {
135135
len++

src/main/kotlin/g3301_3400/s3372_maximize_the_number_of_target_nodes_after_connecting_trees_i/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class Solution {
138138
run {
139139
var i = 0
140140
while (k != 0 && i < m) {
141-
max = max(max.toDouble(), b[i][k - 1].toDouble()).toInt()
141+
max = max(max, b[i][k - 1])
142142
i++
143143
}
144144
}

src/main/kotlin/g3301_3400/s3394_check_if_grid_can_be_cut_into_sections/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ class Solution {
9292
if (start >= max && ++cut == 2) {
9393
return true
9494
}
95-
max = max(max.toDouble(), (arr[i] and MASK.toLong()).toInt().toDouble()).toInt()
95+
max = max(max, (arr[i] and MASK.toLong()).toInt())
9696
}
9797
return false
9898
}
9999

100100
companion object {
101-
private val MASK = (1 shl 30) - 1
101+
private const val MASK = (1 shl 30) - 1
102102
}
103103
}
104104
```

src/main/kotlin/g3401_3500/s3411_maximum_subarray_with_equal_products/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Solution {
7878
currGCD = gcd(currGCD, nums[j])
7979
currLCM = lcm(currLCM, nums[j])
8080
if (currPro == currLCM * currGCD) {
81-
maxL = max(maxL.toDouble(), (j - i + 1).toDouble()).toInt()
81+
maxL = max(maxL, j - i + 1)
8282
}
8383
}
8484
}

src/main/kotlin/g3401_3500/s3413_maximum_coins_from_k_consecutive_bags/readme.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,31 @@ import kotlin.math.max
5151

5252
class Solution {
5353
fun maximumCoins(coins: Array<IntArray>, k: Int): Long {
54-
coins.sortWith { a: IntArray?, b: IntArray? -> a!![0] - b!![0] }
54+
coins.sortWith { a: IntArray, b: IntArray -> a[0] - b[0] }
5555
val n = coins.size
5656
var res: Long = 0
5757
var cur: Long = 0
5858
var j = 0
5959
for (ints in coins) {
6060
while (j < n && coins[j][1] <= ints[0] + k - 1) {
61-
cur += (coins[j][1] - coins[j][0] + 1).toLong() * coins[j][2]
61+
cur += (coins[j][1] - coins[j][0] + 1) * coins[j][2]
6262
j++
6363
}
6464
if (j < n) {
65-
val part = max(0.0, (ints[0] + k - 1 - coins[j][0] + 1).toDouble()).toLong() * coins[j][2]
66-
res = max(res.toDouble(), (cur + part).toDouble()).toLong()
65+
val part = max(0, ints[0] + k - 1 - coins[j][0] + 1) * coins[j][2]
66+
res = max(res, cur + part)
6767
}
68-
cur -= (ints[1] - ints[0] + 1).toLong() * ints[2]
68+
cur -= (ints[1] - ints[0] + 1) * ints[2]
6969
}
7070
cur = 0
7171
j = 0
7272
for (coin in coins) {
73-
cur += (coin[1] - coin[0] + 1).toLong() * coin[2]
73+
cur += (coin[1] - coin[0] + 1) * coin[2]
7474
while (coins[j][1] < coin[1] - k + 1) {
75-
cur -= (coins[j][1] - coins[j][0] + 1).toLong() * coins[j][2]
75+
cur -= (coins[j][1] - coins[j][0] + 1) * coins[j][2]
7676
j++
7777
}
78-
val part = max(0.0, (coin[1] - k - coins[j][0] + 1).toDouble()).toLong() * coins[j][2]
78+
val part = max(0, coin[1] - k - coins[j][0] + 1) * coins[j][2]
7979
res = max(res, (cur - part))
8080
}
8181
return res

src/main/kotlin/g3401_3500/s3459_length_of_longest_v_shaped_diagonal_segment/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Solution {
104104
for (j in 0..<m) {
105105
if (g[i][j] == 1) {
106106
for (d in 0..3) {
107-
res = max(res.toDouble(), dp(i, j, 1, d, 1).toDouble()).toInt()
107+
res = max(res, dp(i, j, 1, d, 1))
108108
}
109109
}
110110
}

src/main/kotlin/g3401_3500/s3479_fruits_into_baskets_iii/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Solution {
6969
seg[size + i] = 0
7070
}
7171
for (i in size - 1 downTo 1) {
72-
seg[i] = max(seg[i shl 1].toDouble(), seg[i shl 1 or 1].toDouble()).toInt()
72+
seg[i] = max(seg[i shl 1], seg[i shl 1 or 1])
7373
}
7474
var ans = 0
7575
for (f in fruits) {
@@ -95,7 +95,7 @@ class Solution {
9595
seg[i] = `val`
9696
i /= 2
9797
while (i > 0) {
98-
seg[i] = max(seg[i shl 1].toDouble(), seg[i shl 1 or 1].toDouble()).toInt()
98+
seg[i] = max(seg[i shl 1], seg[i shl 1 or 1])
9999
i /= 2
100100
}
101101
}

src/main/kotlin/g3501_3600/s3508_implement_router/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Router(private val size: Int) {
132132
return true
133133
}
134134

135-
fun forwardPacket(): IntArray? {
135+
fun forwardPacket(): IntArray {
136136
if (q.isEmpty()) {
137137
return intArrayOf()
138138
}
@@ -166,7 +166,7 @@ class Router(private val size: Int) {
166166
if (lower == -1 || higher == -1) {
167167
0
168168
} else {
169-
max(0.0, (higher - lower + 1).toDouble()).toInt()
169+
max(0, higher - lower + 1)
170170
}
171171
} else {
172172
0

0 commit comments

Comments
 (0)