3452. Sum of Good Numbers Easy

@problem@discussion
#Array



1/**
2 * [3452] Sum of Good Numbers
3 *
4 * Given an array of integers nums and an integer k, an element nums[i] is considered good if it is strictly greater than the elements at indices i - k and i + k (if those indices exist). If neither of these indices exists, nums[i] is still considered good.
5 * Return the sum of all the good elements in the array.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [1,3,2,1,5,4], k = 2</span>
10 * Output: <span class="example-io">12</span>
11 * Explanation:
12 * The good numbers are nums[1] = 3, nums[4] = 5, and nums[5] = 4 because they are strictly greater than the numbers at indices i - k and i + k.
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">nums = [2,1], k = 1</span>
17 * Output: <span class="example-io">2</span>
18 * Explanation:
19 * The only good number is nums[0] = 2 because it is strictly greater than nums[1].
20 * </div>
21 *  
22 * Constraints:
23 * 
24 * 	2 <= nums.length <= 100
25 * 	1 <= nums[i] <= 1000
26 * 	1 <= k <= floor(nums.length / 2)
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/sum-of-good-numbers/
32// discuss: https://leetcode.com/problems/sum-of-good-numbers/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn sum_of_good_numbers(nums: Vec<i32>, k: i32) -> i32 {
38        0
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_3452() {
50    }
51}
52

Back
© 2026 bowen.ge All Rights Reserved.