File tree Expand file tree Collapse file tree 14 files changed +46
-35
lines changed
src/main/kotlin/g3601_3700
s3627_maximum_median_sum_of_subsequences_of_size_3
s3628_maximum_number_of_subsequences_after_one_inserting
s3629_minimum_jumps_to_reach_end_via_prime_teleportation
s3633_earliest_finish_time_for_land_and_water_rides_i
s3634_minimum_removals_to_balance_array
s3635_earliest_finish_time_for_land_and_water_rides_ii
s3636_threshold_majority_queries
s3638_maximum_balanced_shipments
s3639_minimum_time_to_activate_string
s3643_flip_square_submatrix_vertically
s3645_maximum_total_from_optimal_activation_order
s3646_next_special_palindrome_number Expand file tree Collapse file tree 14 files changed +46
-35
lines changed Original file line number Diff line number Diff line change 11package 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
56class Solution {
67 fun maximumMedianSum (nums : IntArray ): Long {
Original file line number Diff line number Diff line change 11package 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
56class Solution {
67 fun numOfSubsequences (s : String ): Long {
Original file line number Diff line number Diff line change 11package 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
56import java.util.ArrayDeque
67import kotlin.math.max
Original file line number Diff line number Diff line change 11package 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
56import kotlin.math.max
67import kotlin.math.min
Original file line number Diff line number Diff line change 11package 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
56import kotlin.math.max
67
Original file line number Diff line number Diff line change 11package 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
56import kotlin.math.max
67import kotlin.math.min
Original file line number Diff line number Diff line change 11package 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
56import java.util.TreeSet
67import kotlin.math.max
Original file line number Diff line number Diff line change 11package 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_03_Time_1_ms_(100.00%)_Space_43.69_MB_(100.00%)
44
55class Solution {
66 fun isTrionic (nums : IntArray ): Boolean {
Original file line number Diff line number Diff line change 11package 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
56import kotlin.math.max
67
Original file line number Diff line number Diff line change 11package 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
76class 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}
You can’t perform that action at this time.
0 commit comments