|
| 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