diff --git a/src/main/kotlin/g2801_2900/s2865_beautiful_towers_i/Solution.kt b/src/main/kotlin/g2801_2900/s2865_beautiful_towers_i/Solution.kt index b1bb0e9c3..c016a4e94 100644 --- a/src/main/kotlin/g2801_2900/s2865_beautiful_towers_i/Solution.kt +++ b/src/main/kotlin/g2801_2900/s2865_beautiful_towers_i/Solution.kt @@ -10,12 +10,12 @@ class Solution { var ans = maxHeights[pickId].toLong() var min = maxHeights[pickId].toLong() for (i in pickId - 1 downTo 0) { - min = min(min.toDouble(), maxHeights[i].toDouble()).toLong() + min = min(min, maxHeights[i].toLong()) ans += min } min = maxHeights[pickId].toLong() for (i in pickId + 1 until maxHeights.size) { - min = min(min.toDouble(), maxHeights[i].toDouble()).toLong() + min = min(min, maxHeights[i].toLong()) ans += min } return ans @@ -30,7 +30,7 @@ class Solution { maxHeights[i] >= maxHeights[i + 1] ) ) { - ans = max(ans.toDouble(), `fun`(maxHeights, i).toDouble()).toLong() + ans = max(ans, `fun`(maxHeights, i)) } } return ans diff --git a/src/main/kotlin/g2801_2900/s2874_maximum_value_of_an_ordered_triplet_ii/Solution.kt b/src/main/kotlin/g2801_2900/s2874_maximum_value_of_an_ordered_triplet_ii/Solution.kt index 0b3cb0129..0d5cd25c4 100644 --- a/src/main/kotlin/g2801_2900/s2874_maximum_value_of_an_ordered_triplet_ii/Solution.kt +++ b/src/main/kotlin/g2801_2900/s2874_maximum_value_of_an_ordered_triplet_ii/Solution.kt @@ -10,14 +10,14 @@ class Solution { var tempMax = nums[0] for (i in 1 until diff.size - 1) { diff[i] = tempMax - nums[i] - tempMax = max(tempMax.toDouble(), nums[i].toDouble()).toInt() + tempMax = max(tempMax, nums[i]) } var max = Long.MIN_VALUE tempMax = nums[nums.size - 1] for (i in nums.size - 2 downTo 1) { - max = max(max.toDouble(), (tempMax.toLong() * diff[i]).toDouble()).toLong() - tempMax = max(tempMax.toDouble(), nums[i].toDouble()).toInt() + max = max(max, tempMax.toLong() * diff[i]) + tempMax = max(tempMax, nums[i]) } - return max(max.toDouble(), 0.0).toLong() + return max(max, 0) } } diff --git a/src/main/kotlin/g2801_2900/s2896_apply_operations_to_make_two_strings_equal/Solution.kt b/src/main/kotlin/g2801_2900/s2896_apply_operations_to_make_two_strings_equal/Solution.kt index 75a85ac82..99a673082 100644 --- a/src/main/kotlin/g2801_2900/s2896_apply_operations_to_make_two_strings_equal/Solution.kt +++ b/src/main/kotlin/g2801_2900/s2896_apply_operations_to_make_two_strings_equal/Solution.kt @@ -21,14 +21,12 @@ class Solution { } val dp = IntArray(m) dp[0] = 0 - dp[1] = min(x.toDouble(), (diffs[1] - diffs[0]).toDouble()).toInt() + dp[1] = min(x, diffs[1] - diffs[0]) for (i in 2 until m) { if ((i and 1) == 1) { - dp[i] = min((dp[i - 1] + x).toDouble(), (dp[i - 2] + diffs[i] - diffs[i - 1]).toDouble()) - .toInt() + dp[i] = min(dp[i - 1] + x, dp[i - 2] + diffs[i] - diffs[i - 1]) } else { - dp[i] = min(dp[i - 1].toDouble(), (dp[i - 2] + diffs[i] - diffs[i - 1]).toDouble()) - .toInt() + dp[i] = min(dp[i - 1], dp[i - 2] + diffs[i] - diffs[i - 1]) } } return dp[m - 1] diff --git a/src/main/kotlin/g2901_3000/s2908_minimum_sum_of_mountain_triplets_i/Solution.kt b/src/main/kotlin/g2901_3000/s2908_minimum_sum_of_mountain_triplets_i/Solution.kt index 52dd6ef71..59ac675e6 100644 --- a/src/main/kotlin/g2901_3000/s2908_minimum_sum_of_mountain_triplets_i/Solution.kt +++ b/src/main/kotlin/g2901_3000/s2908_minimum_sum_of_mountain_triplets_i/Solution.kt @@ -15,7 +15,7 @@ class Solution { for (k in j + 1 until nums.size) { if (nums[i] < nums[j] && nums[k] < nums[j]) { val min = nums[i] + nums[k] + nums[j] - output = min(min.toDouble(), output.toDouble()).toInt() + output = min(min, output) } } } diff --git a/src/main/kotlin/g2901_3000/s2909_minimum_sum_of_mountain_triplets_ii/Solution.kt b/src/main/kotlin/g2901_3000/s2909_minimum_sum_of_mountain_triplets_ii/Solution.kt index 5ab6dadb8..2a0517615 100644 --- a/src/main/kotlin/g2901_3000/s2909_minimum_sum_of_mountain_triplets_ii/Solution.kt +++ b/src/main/kotlin/g2901_3000/s2909_minimum_sum_of_mountain_triplets_ii/Solution.kt @@ -32,8 +32,7 @@ class Solution { var ans = Int.MAX_VALUE for (i in 0 until n) { if (leftSmallest[i] != -1 && rightSmallest[i] != -1) { - ans = min(ans.toDouble(), (leftSmallest[i] + rightSmallest[i] + nums[i]).toDouble()) - .toInt() + ans = min(ans, leftSmallest[i] + rightSmallest[i] + nums[i]) } } if (ans == Int.MAX_VALUE) { diff --git a/src/main/kotlin/g2901_3000/s2911_minimum_changes_to_make_k_semi_palindromes/Solution.kt b/src/main/kotlin/g2901_3000/s2911_minimum_changes_to_make_k_semi_palindromes/Solution.kt index c33073ca4..0459200de 100644 --- a/src/main/kotlin/g2901_3000/s2911_minimum_changes_to_make_k_semi_palindromes/Solution.kt +++ b/src/main/kotlin/g2901_3000/s2911_minimum_changes_to_make_k_semi_palindromes/Solution.kt @@ -28,7 +28,7 @@ class Solution { } var min = INF for (j in (k - 1) * 2 until (i - 1)) { - min = min(min.toDouble(), (calc(j, k - 1) + change(j, i)).toDouble()).toInt() + min = min(min, calc(j, k - 1) + change(j, i)) } dp[i][k] = min return min diff --git a/src/main/kotlin/g2901_3000/s2926_maximum_balanced_subsequence_sum/Solution.kt b/src/main/kotlin/g2901_3000/s2926_maximum_balanced_subsequence_sum/Solution.kt index e5f94dcf6..3dbd752bf 100644 --- a/src/main/kotlin/g2901_3000/s2926_maximum_balanced_subsequence_sum/Solution.kt +++ b/src/main/kotlin/g2901_3000/s2926_maximum_balanced_subsequence_sum/Solution.kt @@ -68,7 +68,7 @@ class Solution { var index = index var result: Long = 0 while (index > 0) { - result = max(tree[index].toDouble(), result.toDouble()).toLong() + result = max(tree[index], result) index -= lowbit(index) } return result diff --git a/src/main/kotlin/g2901_3000/s2944_minimum_number_of_coins_for_fruits/Solution.kt b/src/main/kotlin/g2901_3000/s2944_minimum_number_of_coins_for_fruits/Solution.kt index 786339a01..43b0ac5d1 100644 --- a/src/main/kotlin/g2901_3000/s2944_minimum_number_of_coins_for_fruits/Solution.kt +++ b/src/main/kotlin/g2901_3000/s2944_minimum_number_of_coins_for_fruits/Solution.kt @@ -16,7 +16,7 @@ class Solution { if (acquired + 1 < n) { var min = Int.MAX_VALUE for (j in acquired + 1 downTo i + 1) { - min = min(min.toDouble(), dp[j].toDouble()).toInt() + min = min(min, dp[j]) } dp[i] = prices[i] + min } else { diff --git a/src/main/kotlin/g2901_3000/s2954_count_the_number_of_infection_sequences/Solution.kt b/src/main/kotlin/g2901_3000/s2954_count_the_number_of_infection_sequences/Solution.kt index a5028fd81..dae6ef9db 100644 --- a/src/main/kotlin/g2901_3000/s2954_count_the_number_of_infection_sequences/Solution.kt +++ b/src/main/kotlin/g2901_3000/s2954_count_the_number_of_infection_sequences/Solution.kt @@ -40,7 +40,7 @@ class Solution { var res: Long = 1 for (i in 1 until sick.size) { val group = sick[i] - sick[i - 1] - 1 - res = res * modPow(2, max(0.0, (group - 1).toDouble()).toInt(), MOD) % MOD + res = res * modPow(2, max(0, group - 1), MOD) % MOD res = res * binomCoeff(sick[i] - i, group) % MOD } return (res * binomCoeff(n - sick.size, n - sick[sick.size - 1] - 1) % MOD).toInt() diff --git a/src/main/kotlin/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/Solution.kt b/src/main/kotlin/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/Solution.kt index baf00bbda..5f0d7bc58 100644 --- a/src/main/kotlin/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/Solution.kt +++ b/src/main/kotlin/g2901_3000/s2958_length_of_longest_subarray_with_at_most_k_frequency/Solution.kt @@ -10,8 +10,8 @@ class Solution { var m1 = Int.MIN_VALUE var m2 = Int.MAX_VALUE for (num in nums) { - m1 = max(m1.toDouble(), num.toDouble()).toInt() - m2 = min(m2.toDouble(), num.toDouble()).toInt() + m1 = max(m1, num) + m2 = min(m2, num) } var max = 0 val f = IntArray(m1 - m2 + 1) diff --git a/src/main/kotlin/g3001_3100/s3039_apply_operations_to_make_string_empty/Solution.kt b/src/main/kotlin/g3001_3100/s3039_apply_operations_to_make_string_empty/Solution.kt index ff31c1773..f3f76c0b5 100644 --- a/src/main/kotlin/g3001_3100/s3039_apply_operations_to_make_string_empty/Solution.kt +++ b/src/main/kotlin/g3001_3100/s3039_apply_operations_to_make_string_empty/Solution.kt @@ -14,7 +14,7 @@ class Solution { val sb = StringBuilder() for (c in ar) { freq[c.code - 'a'.code]++ - max = max(freq[c.code - 'a'.code].toDouble(), max.toDouble()).toInt() + max = max(freq[c.code - 'a'.code], max) } for (i in n - 1 downTo 0) { if (freq[ar[i].code - 'a'.code] == max) { diff --git a/src/main/kotlin/g3001_3100/s3074_apple_redistribution_into_boxes/Solution.kt b/src/main/kotlin/g3001_3100/s3074_apple_redistribution_into_boxes/Solution.kt index aebfae3cb..3a1237aa7 100644 --- a/src/main/kotlin/g3001_3100/s3074_apple_redistribution_into_boxes/Solution.kt +++ b/src/main/kotlin/g3001_3100/s3074_apple_redistribution_into_boxes/Solution.kt @@ -15,7 +15,7 @@ class Solution { var max = 0 for (j in capacity) { count[j]++ - max = max(max.toDouble(), j.toDouble()).toInt() + max = max(max, j) } for (i in max downTo 0) { if (count[i] >= 1) { diff --git a/src/main/kotlin/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/Solution.kt b/src/main/kotlin/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/Solution.kt index 8c51f72f2..669cac549 100644 --- a/src/main/kotlin/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/Solution.kt +++ b/src/main/kotlin/g3001_3100/s3076_shortest_uncommon_substring_in_an_array/Solution.kt @@ -28,8 +28,7 @@ class Solution { val curLen = search( cs, i, - min(m.toDouble(), (i + resultLen).toDouble()) - .toInt(), + min(m, (i + resultLen)), k, ) if (curLen != -1) { diff --git a/src/main/kotlin/g3001_3100/s3086_minimum_moves_to_pick_k_ones/Solution.kt b/src/main/kotlin/g3001_3100/s3086_minimum_moves_to_pick_k_ones/Solution.kt index b5ebb00a6..3751e8151 100644 --- a/src/main/kotlin/g3001_3100/s3086_minimum_moves_to_pick_k_ones/Solution.kt +++ b/src/main/kotlin/g3001_3100/s3086_minimum_moves_to_pick_k_ones/Solution.kt @@ -53,7 +53,7 @@ class Solution { val area1 = (mid - l + 1).toLong() * median val area2 = (r - mid).toLong() * median val curRes = area1 - sum1 + sum2 - area2 - res = min(res.toDouble(), curRes.toDouble()).toLong() + res = min(res, curRes) l++ } res += 2L * maxChanges diff --git a/src/main/kotlin/g3001_3100/s3092_most_frequent_ids/Solution.kt b/src/main/kotlin/g3001_3100/s3092_most_frequent_ids/Solution.kt index 02fc4b027..4f038505b 100644 --- a/src/main/kotlin/g3001_3100/s3092_most_frequent_ids/Solution.kt +++ b/src/main/kotlin/g3001_3100/s3092_most_frequent_ids/Solution.kt @@ -10,7 +10,7 @@ class Solution { var max = Int.MIN_VALUE val n = nums.size for (num in nums) { - max = max(max.toDouble(), num.toDouble()).toInt() + max = max(max, num) } val bins = LongArray(max + 1) var mostFrequentID = 0 diff --git a/src/main/kotlin/g3101_3200/s3121_count_the_number_of_special_characters_ii/Solution.kt b/src/main/kotlin/g3101_3200/s3121_count_the_number_of_special_characters_ii/Solution.kt index 19b823d66..bdb7ffaaf 100644 --- a/src/main/kotlin/g3101_3200/s3121_count_the_number_of_special_characters_ii/Solution.kt +++ b/src/main/kotlin/g3101_3200/s3121_count_the_number_of_special_characters_ii/Solution.kt @@ -14,7 +14,7 @@ class Solution { for (i in word.indices) { val a = word[i] if (a.code < 91) { - capital[a.code - 65] = min(capital[a.code - 65].toDouble(), i.toDouble()).toInt() + capital[a.code - 65] = min(capital[a.code - 65], i) } else { small[a.code - 97] = i } diff --git a/src/main/kotlin/g3101_3200/s3161_block_placement_queries/Solution.kt b/src/main/kotlin/g3101_3200/s3161_block_placement_queries/Solution.kt index 5b64e0daf..cd1b192e2 100644 --- a/src/main/kotlin/g3101_3200/s3161_block_placement_queries/Solution.kt +++ b/src/main/kotlin/g3101_3200/s3161_block_placement_queries/Solution.kt @@ -70,7 +70,7 @@ class Solution { right.parent[x] = next bit.update(next, next - pre) } else { - val maxGap = max(bit.query(pre).toDouble(), (x - pre).toDouble()).toInt() + val maxGap = max(bit.query(pre), x - pre) ans[index--] = maxGap >= q[2] } } @@ -83,7 +83,7 @@ class Solution { fun update(i: Int, v: Int) { var i = i while (i < n) { - tree[i] = max(tree[i].toDouble(), v.toDouble()).toInt() + tree[i] = max(tree[i], v) i += i and -i } } @@ -92,7 +92,7 @@ class Solution { var i = i var result = 0 while (i > 0) { - result = max(result.toDouble(), tree[i].toDouble()).toInt() + result = max(result, tree[i]) i = i and i - 1 } return result diff --git a/src/main/kotlin/g3101_3200/s3196_maximize_total_cost_of_alternating_subarrays/Solution.kt b/src/main/kotlin/g3101_3200/s3196_maximize_total_cost_of_alternating_subarrays/Solution.kt index 24e11fee2..7be6ee00b 100644 --- a/src/main/kotlin/g3101_3200/s3196_maximize_total_cost_of_alternating_subarrays/Solution.kt +++ b/src/main/kotlin/g3101_3200/s3196_maximize_total_cost_of_alternating_subarrays/Solution.kt @@ -10,7 +10,7 @@ class Solution { var addResult = nums[0].toLong() var subResult = nums[0].toLong() for (i in 1 until n) { - val tempAdd = (max(addResult.toDouble(), subResult.toDouble()) + nums[i]).toLong() + val tempAdd = max(addResult, subResult) + nums[i] val tempSub = addResult - nums[i] addResult = tempAdd subResult = tempSub diff --git a/src/main/kotlin/g3201_3300/s3207_maximum_points_after_enemy_battles/Solution.kt b/src/main/kotlin/g3201_3300/s3207_maximum_points_after_enemy_battles/Solution.kt index a25c924ea..6192f141c 100644 --- a/src/main/kotlin/g3201_3300/s3207_maximum_points_after_enemy_battles/Solution.kt +++ b/src/main/kotlin/g3201_3300/s3207_maximum_points_after_enemy_battles/Solution.kt @@ -9,7 +9,7 @@ class Solution { val n = enemyEnergies.size var min = enemyEnergies[0] for (i in 1 until n) { - min = min(min.toDouble(), enemyEnergies[i].toDouble()).toInt() + min = min(min, enemyEnergies[i]) } if (currentEnergy == 0 || currentEnergy < min) { return 0 diff --git a/src/main/kotlin/g3201_3300/s3272_find_the_count_of_good_integers/Solution.kt b/src/main/kotlin/g3201_3300/s3272_find_the_count_of_good_integers/Solution.kt index 2bf0e53a5..72c34333c 100644 --- a/src/main/kotlin/g3201_3300/s3272_find_the_count_of_good_integers/Solution.kt +++ b/src/main/kotlin/g3201_3300/s3272_find_the_count_of_good_integers/Solution.kt @@ -73,7 +73,7 @@ class Solution { private fun allKPalindromes(n: Int, k: Int): List { val ans = StringBuilder(n) - ans.append("0".repeat(max(0.0, n.toDouble()).toInt())) + ans.append("0".repeat(max(0, n))) val rem = IntArray(n) rem[0] = 1 for (i in 1 until n) { diff --git a/src/main/kotlin/g3301_3400/s3327_check_if_dfs_strings_are_palindromes/Solution.kt b/src/main/kotlin/g3301_3400/s3327_check_if_dfs_strings_are_palindromes/Solution.kt index a8b5f8209..4d39f21ad 100644 --- a/src/main/kotlin/g3301_3400/s3327_check_if_dfs_strings_are_palindromes/Solution.kt +++ b/src/main/kotlin/g3301_3400/s3327_check_if_dfs_strings_are_palindromes/Solution.kt @@ -66,7 +66,7 @@ class Solution { for (i in 2..= max && ++cut == 2) { return true } - max = max(max.toDouble(), (arr[i] and MASK.toLong()).toInt().toDouble()).toInt() + max = max(max, (arr[i] and MASK.toLong()).toInt()) } return false } companion object { - private val MASK = (1 shl 30) - 1 + private const val MASK = (1 shl 30) - 1 } } diff --git a/src/main/kotlin/g3401_3500/s3411_maximum_subarray_with_equal_products/Solution.kt b/src/main/kotlin/g3401_3500/s3411_maximum_subarray_with_equal_products/Solution.kt index 9205e81d6..195e71017 100644 --- a/src/main/kotlin/g3401_3500/s3411_maximum_subarray_with_equal_products/Solution.kt +++ b/src/main/kotlin/g3401_3500/s3411_maximum_subarray_with_equal_products/Solution.kt @@ -26,7 +26,7 @@ class Solution { currGCD = gcd(currGCD, nums[j]) currLCM = lcm(currLCM, nums[j]) if (currPro == currLCM * currGCD) { - maxL = max(maxL.toDouble(), (j - i + 1).toDouble()).toInt() + maxL = max(maxL, j - i + 1) } } } diff --git a/src/main/kotlin/g3401_3500/s3413_maximum_coins_from_k_consecutive_bags/Solution.kt b/src/main/kotlin/g3401_3500/s3413_maximum_coins_from_k_consecutive_bags/Solution.kt index b8e792f38..8d0262012 100644 --- a/src/main/kotlin/g3401_3500/s3413_maximum_coins_from_k_consecutive_bags/Solution.kt +++ b/src/main/kotlin/g3401_3500/s3413_maximum_coins_from_k_consecutive_bags/Solution.kt @@ -7,31 +7,31 @@ import kotlin.math.max class Solution { fun maximumCoins(coins: Array, k: Int): Long { - coins.sortWith { a: IntArray?, b: IntArray? -> a!![0] - b!![0] } + coins.sortWith { a: IntArray, b: IntArray -> a[0] - b[0] } val n = coins.size var res: Long = 0 var cur: Long = 0 var j = 0 for (ints in coins) { while (j < n && coins[j][1] <= ints[0] + k - 1) { - cur += (coins[j][1] - coins[j][0] + 1).toLong() * coins[j][2] + cur += (coins[j][1] - coins[j][0] + 1) * coins[j][2] j++ } if (j < n) { - val part = max(0.0, (ints[0] + k - 1 - coins[j][0] + 1).toDouble()).toLong() * coins[j][2] - res = max(res.toDouble(), (cur + part).toDouble()).toLong() + val part = max(0, ints[0] + k - 1 - coins[j][0] + 1) * coins[j][2] + res = max(res, cur + part) } - cur -= (ints[1] - ints[0] + 1).toLong() * ints[2] + cur -= (ints[1] - ints[0] + 1) * ints[2] } cur = 0 j = 0 for (coin in coins) { - cur += (coin[1] - coin[0] + 1).toLong() * coin[2] + cur += (coin[1] - coin[0] + 1) * coin[2] while (coins[j][1] < coin[1] - k + 1) { - cur -= (coins[j][1] - coins[j][0] + 1).toLong() * coins[j][2] + cur -= (coins[j][1] - coins[j][0] + 1) * coins[j][2] j++ } - val part = max(0.0, (coin[1] - k - coins[j][0] + 1).toDouble()).toLong() * coins[j][2] + val part = max(0, coin[1] - k - coins[j][0] + 1) * coins[j][2] res = max(res, (cur - part)) } return res diff --git a/src/main/kotlin/g3401_3500/s3459_length_of_longest_v_shaped_diagonal_segment/Solution.kt b/src/main/kotlin/g3401_3500/s3459_length_of_longest_v_shaped_diagonal_segment/Solution.kt index 588bf6f23..73edcc289 100644 --- a/src/main/kotlin/g3401_3500/s3459_length_of_longest_v_shaped_diagonal_segment/Solution.kt +++ b/src/main/kotlin/g3401_3500/s3459_length_of_longest_v_shaped_diagonal_segment/Solution.kt @@ -31,7 +31,7 @@ class Solution { for (j in 0.. 0) { - seg[i] = max(seg[i shl 1].toDouble(), seg[i shl 1 or 1].toDouble()).toInt() + seg[i] = max(seg[i shl 1], seg[i shl 1 or 1]) i /= 2 } } diff --git a/src/main/kotlin/g3501_3600/s3508_implement_router/Router.kt b/src/main/kotlin/g3501_3600/s3508_implement_router/Router.kt index cef9f8872..70730ed85 100644 --- a/src/main/kotlin/g3501_3600/s3508_implement_router/Router.kt +++ b/src/main/kotlin/g3501_3600/s3508_implement_router/Router.kt @@ -51,7 +51,7 @@ class Router(private val size: Int) { return true } - fun forwardPacket(): IntArray? { + fun forwardPacket(): IntArray { if (q.isEmpty()) { return intArrayOf() } @@ -85,7 +85,7 @@ class Router(private val size: Int) { if (lower == -1 || higher == -1) { 0 } else { - max(0.0, (higher - lower + 1).toDouble()).toInt() + max(0, higher - lower + 1) } } else { 0