Simple Approach - Easy to Understand - Python/Java/C/C++
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python []
class Solution:
    def sumOfGoodNumbers(self, nums: List[int], k: int) -> int:
        ans = 0
        for i in range(len(nums)):
            check = True

            if i - k >= 0 and nums[i] <= nums[i - k]:
                check = False

            if i + k < len(nums) and nums[i] <= nums[i + k]:
                check = False

            if check:
                ans += nums[i]
        return ans
            
```
```java []
class Solution {
    public int sumOfGoodNumbers(int[] nums, int k) {
        int ans = 0;
        for (int i = 0; i < nums.length; i++) {
            boolean check = true;

            if (i - k >= 0 && nums[i] <= nums[i - k]) {
                check = false;
            }

            if (i + k < nums.length && nums[i] <= nums[i + k]) {
                check = false;
            }

            if (check) {
                ans += nums[i];
            }
        }
        return ans;
    }
}
```
```c []
int sumOfGoodNumbers(int* nums, int numsSize, int k) {
    int ans = 0;
    for (int i = 0; i < numsSize; i++) {
        int check = 1; 

        if (i - k >= 0 && nums[i] <= nums[i - k]) {
            check = 0; 
        }

        if (i + k < numsSize && nums[i] <= nums[i + k]) {
            check = 0;
        }

        if (check) {
            ans += nums[i];
        }
    }
    return ans;
}
```
```cpp []
class Solution {
public:
    int sumOfGoodNumbers(vector<int>& nums, int k) {
        int ans = 0;
        for (int i = 0; i < nums.size(); i++) {
            bool check = true;

            if (i - k >= 0 && nums[i] <= nums[i - k]) {
                check = false;
            }

            if (i + k < nums.size() && nums[i] <= nums[i + k]) {
                check = false;
            }

            if (check) {
                ans += nums[i];
            }
        }
        return ans;
    }
};
```
['Java']