Skip to content

Commit 609a2f4

Browse files
committed
1793. Maximum Score of a Good Subarray: RETRY
1 parent 523e709 commit 609a2f4

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,3 +1351,4 @@ mod s1787_make_the_xor_of_all_segments_equal_to_zero;
13511351
mod s1790_check_if_one_string_swap_can_make_strings_equal;
13521352
mod s1791_find_center_of_star_graph;
13531353
mod s1792_maximum_average_pass_ratio;
1354+
mod s1793_maximum_score_of_a_good_subarray;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* [1793] Maximum Score of a Good Subarray
3+
*
4+
* You are given an array of integers nums (0-indexed) and an integer k.
5+
* The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j.
6+
* Return the maximum possible score of a good subarray.
7+
*
8+
* Example 1:
9+
*
10+
* Input: nums = [1,4,3,7,4,5], k = 3
11+
* Output: 15
12+
* Explanation: The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15.
13+
*
14+
* Example 2:
15+
*
16+
* Input: nums = [5,5,4,5,4,1,1,1], k = 0
17+
* Output: 20
18+
* Explanation: The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.
19+
*
20+
*
21+
* Constraints:
22+
*
23+
* 1 <= nums.length <= 10^5
24+
* 1 <= nums[i] <= 2 * 10^4
25+
* 0 <= k < nums.length
26+
*
27+
*/
28+
pub struct Solution {}
29+
30+
// problem: https://leetcode.com/problems/maximum-score-of-a-good-subarray/
31+
// discuss: https://leetcode.com/problems/maximum-score-of-a-good-subarray/discuss/?currentPage=1&orderBy=most_votes&query=
32+
33+
// submission codes start here
34+
35+
impl Solution {
36+
pub fn maximum_score(nums: Vec<i32>, k: i32) -> i32 {
37+
0
38+
}
39+
}
40+
41+
// submission codes end
42+
43+
#[cfg(test)]
44+
mod tests {
45+
use super::*;
46+
47+
#[test]
48+
#[ignore]
49+
fn test_1793_example_1() {
50+
let nums = vec![1, 4, 3, 7, 4, 5];
51+
let k = 3;
52+
53+
let result = 15;
54+
55+
assert_eq!(Solution::maximum_score(nums, k), result);
56+
}
57+
58+
#[test]
59+
#[ignore]
60+
fn test_1793_example_2() {
61+
let nums = vec![5, 5, 4, 5, 4, 1, 1, 1];
62+
let k = 0;
63+
64+
let result = 20;
65+
66+
assert_eq!(Solution::maximum_score(nums, k), result);
67+
}
68+
}

0 commit comments

Comments
 (0)