Skip to content

Commit 748c192

Browse files
committed
Updated tasks
1 parent 9519776 commit 748c192

File tree

2 files changed

+30
-30
lines changed
  • src/main/kotlin/g3601_3700

2 files changed

+30
-30
lines changed
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package g3601_3700.s3675_minimum_operations_to_transform_string
22

3-
// #Medium #Weekly_Contest_466 #2025_09_07_Time_84_ms_(100.00%)_Space_56.99_MB_(100.00%)
3+
// #Medium #Weekly_Contest_466 #2025_09_14_Time_6_ms_(97.92%)_Space_57.75_MB_(43.75%)
44

55
class Solution {
66
fun minOperations(s: String): Int {
7-
val set: MutableSet<Char> = HashSet<Char>()
8-
for (ch in s.toCharArray()) {
9-
set.add(ch)
10-
}
11-
if (set.size == 1 && set.contains('a')) {
12-
return 0
13-
}
14-
var minCh = 'z'
15-
for (ch in s.toCharArray()) {
16-
if (ch != 'a' && ch < minCh) {
17-
minCh = ch
7+
val n = s.length
8+
var ans = 0
9+
for (i in 0..<n) {
10+
val c = s.get(i)
11+
if (c != 'a') {
12+
val ops = 'z'.code - c.code + 1
13+
if (ops > ans) {
14+
ans = ops
15+
}
16+
if (ops == 25) {
17+
break
18+
}
1819
}
1920
}
20-
return ('z'.code - minCh.code) + 1
21+
return ans
2122
}
2223
}
Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package g3601_3700.s3676_count_bowl_subarrays
22

3-
// #Medium #Weekly_Contest_466 #2025_09_07_Time_26_ms_(100.00%)_Space_84.36_MB_(100.00%)
4-
5-
import kotlin.math.min
3+
// #Medium #Weekly_Contest_466 #2025_09_14_Time_3_ms_(100.00%)_Space_79.40_MB_(50.00%)
64

75
class Solution {
86
fun bowlSubarrays(nums: IntArray): Long {
9-
val l = nums.size
10-
var ans = 0
11-
val stack: java.util.Deque<Int> = java.util.ArrayDeque<Int>()
12-
for (i in 0..<l) {
13-
while (stack.isNotEmpty() && nums[stack.peek()!!] < nums[i]) {
14-
val mid: Int = stack.pop()!!
15-
if (stack.isNotEmpty()) {
16-
val left: Int = stack.peek()!!
17-
if (min(nums[left], nums[i]) > nums[mid]) {
18-
++ans
19-
}
20-
}
7+
val n = nums.size
8+
var res = n
9+
var pre = 0
10+
for (a in nums) {
11+
if (a > pre) {
12+
res--
13+
pre = a
14+
}
15+
}
16+
pre = 0
17+
for (i in n - 1 downTo 0) {
18+
if (nums[i] > pre) {
19+
res--
20+
pre = nums[i]
2121
}
22-
stack.push(i)
2322
}
24-
return ans.toLong()
23+
return res + 1L
2524
}
2625
}

0 commit comments

Comments
 (0)