Skip to content

Commit 93df966

Browse files
authored
Added tasks 3643-3646
1 parent 33387a1 commit 93df966

File tree

24 files changed

+558
-51
lines changed

24 files changed

+558
-51
lines changed

src/main/kotlin/g3601_3700/s3627_maximum_median_sum_of_subsequences_of_size_3/Solution.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3601_3700.s3627_maximum_median_sum_of_subsequences_of_size_3
22

3-
// #Medium #Weekly_Contest_460 #2025_07_27_Time_46_ms_(91.67%)_Space_133.87_MB_(16.67%)
3+
// #Medium #Array #Math #Sorting #Greedy #Game_Theory #Weekly_Contest_460
4+
// #2025_07_27_Time_46_ms_(91.67%)_Space_133.87_MB_(16.67%)
45

56
class Solution {
67
fun maximumMedianSum(nums: IntArray): Long {

src/main/kotlin/g3601_3700/s3628_maximum_number_of_subsequences_after_one_inserting/Solution.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3601_3700.s3628_maximum_number_of_subsequences_after_one_inserting
22

3-
// #Medium #Weekly_Contest_460 #2025_07_27_Time_13_ms_(100.00%)_Space_48.00_MB_(75.00%)
3+
// #Medium #String #Dynamic_Programming #Greedy #Prefix_Sum #Weekly_Contest_460
4+
// #2025_07_27_Time_13_ms_(100.00%)_Space_48.00_MB_(75.00%)
45

56
class Solution {
67
fun numOfSubsequences(s: String): Long {

src/main/kotlin/g3601_3700/s3629_minimum_jumps_to_reach_end_via_prime_teleportation/Solution.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3601_3700.s3629_minimum_jumps_to_reach_end_via_prime_teleportation
22

3-
// #Medium #Weekly_Contest_460 #2025_07_27_Time_406_ms_(100.00%)_Space_153.64_MB_(100.00%)
3+
// #Medium #Array #Hash_Table #Math #Breadth_First_Search #Number_Theory #Weekly_Contest_460
4+
// #2025_07_27_Time_406_ms_(100.00%)_Space_153.64_MB_(100.00%)
45

56
import java.util.ArrayDeque
67
import kotlin.math.max

src/main/kotlin/g3601_3700/s3633_earliest_finish_time_for_land_and_water_rides_i/Solution.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3601_3700.s3633_earliest_finish_time_for_land_and_water_rides_i
22

3-
// #Easy #Biweekly_Contest_162 #2025_08_03_Time_15_ms_(100.00%)_Space_48.53_MB_(100.00%)
3+
// #Easy #Array #Sorting #Greedy #Binary_Search #Two_Pointers #Biweekly_Contest_162
4+
// #2025_08_03_Time_15_ms_(100.00%)_Space_48.53_MB_(100.00%)
45

56
import kotlin.math.max
67
import kotlin.math.min

src/main/kotlin/g3601_3700/s3634_minimum_removals_to_balance_array/Solution.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3601_3700.s3634_minimum_removals_to_balance_array
22

3-
// #Medium #Biweekly_Contest_162 #2025_08_03_Time_43_ms_(100.00%)_Space_66.87_MB_(100.00%)
3+
// #Medium #Array #Sorting #Sliding_Window #Biweekly_Contest_162
4+
// #2025_08_03_Time_43_ms_(100.00%)_Space_66.87_MB_(100.00%)
45

56
import kotlin.math.max
67

src/main/kotlin/g3601_3700/s3635_earliest_finish_time_for_land_and_water_rides_ii/Solution.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3601_3700.s3635_earliest_finish_time_for_land_and_water_rides_ii
22

3-
// #Medium #Biweekly_Contest_162 #2025_08_03_Time_5_ms_(100.00%)_Space_73.02_MB_(100.00%)
3+
// #Medium #Array #Sorting #Greedy #Binary_Search #Two_Pointers #Biweekly_Contest_162
4+
// #2025_08_03_Time_5_ms_(100.00%)_Space_73.02_MB_(100.00%)
45

56
import kotlin.math.max
67
import kotlin.math.min

src/main/kotlin/g3601_3700/s3636_threshold_majority_queries/Solution.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3601_3700.s3636_threshold_majority_queries
22

3-
// #Hard #Biweekly_Contest_162 #2025_08_03_Time_848_ms_(100.00%)_Space_99.90_MB_(100.00%)
3+
// #Hard #Array #Hash_Table #Binary_Search #Prefix_Sum #Counting #Divide_and_Conquer
4+
// #Biweekly_Contest_162 #2025_08_03_Time_848_ms_(100.00%)_Space_99.90_MB_(100.00%)
45

56
import java.util.TreeSet
67
import kotlin.math.max
Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
package g3601_3700.s3637_trionic_array_i
22

3-
// #Easy #Weekly_Contest_461 #2025_08_03_Time_1_ms_(100.00%)_Space_43.69_MB_(100.00%)
3+
// #Easy #Array #Weekly_Contest_461 #2025_08_14_Time_1_ms_(100.00%)_Space_43.95_MB_(38.57%)
44

55
class Solution {
66
fun isTrionic(nums: IntArray): Boolean {
7-
var p = 0
8-
var q = 0
7+
var i = 1
98
val n = nums.size
10-
for (i in 1..<n - 1) {
11-
if (nums[i - 1] == nums[i]) {
12-
return false
13-
}
14-
if (nums[i - 1] < nums[i] && nums[i] > nums[i + 1]) {
15-
if (p != 0) {
16-
return false
17-
}
18-
p = i
19-
}
20-
if (nums[i - 1] > nums[i] && nums[i] < nums[i + 1]) {
21-
if (p == 0 || q != 0) {
22-
return false
23-
}
24-
q = i
25-
}
9+
while (i < n && nums[i] > nums[i - 1]) {
10+
i++
2611
}
27-
return q > 0
12+
if (i == n || i == 1) {
13+
return false
14+
}
15+
while (i < n && nums[i] < nums[i - 1]) {
16+
i++
17+
}
18+
if (i == n) {
19+
return false
20+
}
21+
while (i < n && nums[i] > nums[i - 1]) {
22+
i++
23+
}
24+
return i == n
2825
}
2926
}

src/main/kotlin/g3601_3700/s3638_maximum_balanced_shipments/Solution.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g3601_3700.s3638_maximum_balanced_shipments
22

3-
// #Medium #Weekly_Contest_461 #2025_08_03_Time_5_ms_(100.00%)_Space_78.25_MB_(100.00%)
3+
// #Medium #Array #Dynamic_Programming #Greedy #Stack #Monotonic_Stack #Weekly_Contest_461
4+
// #2025_08_03_Time_5_ms_(100.00%)_Space_78.25_MB_(100.00%)
45

56
import kotlin.math.max
67

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
package g3601_3700.s3639_minimum_time_to_activate_string
22

3-
// #Medium #Weekly_Contest_461 #2025_08_03_Time_160_ms_(100.00%)_Space_85.36_MB_(100.00%)
4-
5-
import java.util.TreeSet
3+
// #Medium #Array #Binary_Search #Weekly_Contest_461
4+
// #2025_08_14_Time_7_ms_(100.00%)_Space_79.04_MB_(50.00%)
65

76
class Solution {
87
fun minTime(s: String, order: IntArray, k: Int): Int {
98
val n = s.length
10-
// Use a TreeSet to maintain a sorted list of indices
11-
val pos = TreeSet<Int?>()
12-
pos.add(-1)
13-
pos.add(n)
14-
// Iterate through the order of removal
15-
var localK = k
16-
for (t in order.indices) {
9+
var total = n * (n + 1L) / 2
10+
if (total < k) {
11+
return -1
12+
}
13+
val prev = IntArray(n + 1)
14+
val next = IntArray(n + 1)
15+
for (i in 0..<n) {
16+
prev[i] = i - 1
17+
next[i] = i + 1
18+
}
19+
for (t in n - 1 downTo 0) {
1720
val i = order[t]
18-
// Find the elements in the sorted set that bracket the current index 'i'
19-
// 'r' is the smallest element >= i
20-
val r = pos.ceiling(i)
21-
// 'l' is the largest element <= i
22-
val l = pos.floor(i)
23-
// The 'cost' to remove an item is the product of the distances to its neighbors
24-
localK -= ((i - l!!).toLong() * (r!! - i)).toInt()
25-
pos.add(i)
26-
// If the total cost is exhausted, return the current time 't'
27-
if (localK <= 0) {
21+
val left = prev[i]
22+
val right = next[i]
23+
total -= (i - left).toLong() * (right - i)
24+
if (total < k) {
2825
return t
2926
}
27+
if (left >= 0) {
28+
next[left] = right
29+
}
30+
prev[right] = left
3031
}
31-
// If all items are removed and k is not exhausted, return -1
32-
return -1
32+
return 0
3333
}
3434
}

0 commit comments

Comments
 (0)