Skip to content

Practice Sum of Good Numbers

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3452
LeetCode Problem

Sum of Good Numbers

Problem Statement

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. Return the sum of all the good elements in the array.

Source: Sum of Good Numbers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,3,2,1,5,4], k = 2
Output
12

# Example 2

Input
nums = [2,1], k = 1
Output
2

Constraints

2 <= nums.length <= 100
1 <= nums[i] <= 1000
1 <= k <= floor(nums.length / 2)

Related LeetCode Problems

Practice more problems similar to Sum of Good Numbers.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.