File tree Expand file tree Collapse file tree 2 files changed +30
-34
lines changed
s3675_minimum_operations_to_transform_string
s3676_count_bowl_subarrays Expand file tree Collapse file tree 2 files changed +30
-34
lines changed Original file line number Diff line number Diff line change 1
1
package g3601_3700 .s3675_minimum_operations_to_transform_string ;
2
2
3
- // #Medium #Weekly_Contest_466 #2025_09_07_Time_137_ms_(100.00%)_Space_51.85_MB_(100.00%)
4
-
5
- import java .util .HashSet ;
6
- import java .util .Set ;
3
+ // #Medium #Weekly_Contest_466 #2025_09_14_Time_5_ms_(100.00%)_Space_47.93_MB_(95.06%)
7
4
8
5
public class Solution {
9
6
public int minOperations (String s ) {
10
- Set <Character > set = new HashSet <>();
11
- for (char ch : s .toCharArray ()) {
12
- set .add (ch );
13
- }
14
- if (set .size () == 1 && set .contains ('a' )) {
15
- return 0 ;
16
- }
17
- char minCh = 'z' ;
18
- for (char ch : s .toCharArray ()) {
19
- if (ch != 'a' && ch < minCh ) {
20
- minCh = ch ;
7
+ int n = s .length ();
8
+ int ans = 0 ;
9
+ for (int i = 0 ; i < n ; i ++) {
10
+ final char c = s .charAt (i );
11
+ if (c != 'a' ) {
12
+ int ops = 'z' - c + 1 ;
13
+ if (ops > ans ) {
14
+ ans = ops ;
15
+ }
16
+ if (ops == 25 ) {
17
+ break ;
18
+ }
21
19
}
22
20
}
23
- return ( 'z' - minCh ) + 1 ;
21
+ return ans ;
24
22
}
25
23
}
Original file line number Diff line number Diff line change 1
1
package g3601_3700 .s3676_count_bowl_subarrays ;
2
2
3
- // #Medium #Weekly_Contest_466 #2025_09_07_Time_19_ms_(100.00%)_Space_59.30_MB_(100.00%)
4
-
5
- import java .util .ArrayDeque ;
6
- import java .util .Deque ;
3
+ // #Medium #Weekly_Contest_466 #2025_09_14_Time_2_ms_(100.00%)_Space_58.91_MB_(69.85%)
7
4
8
5
public class Solution {
9
6
public long bowlSubarrays (int [] nums ) {
10
- int l = nums .length ;
11
- int ans = 0 ;
12
- Deque <Integer > stack = new ArrayDeque <>();
13
- for (int i = 0 ; i < l ; i ++) {
14
- while (!stack .isEmpty () && nums [stack .peek ()] < nums [i ]) {
15
- int mid = stack .pop ();
16
- if (!stack .isEmpty ()) {
17
- int left = stack .peek ();
18
- if (Math .min (nums [left ], nums [i ]) > nums [mid ]) {
19
- ++ans ;
20
- }
21
- }
7
+ int n = nums .length ;
8
+ int res = n ;
9
+ int pre = 0 ;
10
+ for (int a : nums ) {
11
+ if (a > pre ) {
12
+ res --;
13
+ pre = a ;
14
+ }
15
+ }
16
+ pre = 0 ;
17
+ for (int i = n - 1 ; i >= 0 ; i --) {
18
+ if (nums [i ] > pre ) {
19
+ res --;
20
+ pre = nums [i ];
22
21
}
23
- stack .push (i );
24
22
}
25
- return ans ;
23
+ return res + 1 ;
26
24
}
27
25
}
You can’t perform that action at this time.
0 commit comments