1793. Maximum Score of a Good Subarray Hard
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 */
28pub 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
35impl 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)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_1793() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.