Simple solution - beats 99.98% 🔥
Complexity
Time complexity : O(N)

Space complexity: O(1)
Code

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

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

# Code
```java []
class Solution {
    public int sumOfGoodNumbers(int[] nums, int k) {
        int ans1 = 0;
        for (int i = 0; i < nums.length; i++) {
            boolean ans2 = true;
            if (i - k >= 0 && nums[i] <= nums[i - k]) {
                ans2 = false;
            }
            else if (i + k < nums.length && nums[i] <= nums[i + k]) {
                ans2 = false;
            }
            else {
                ans1 += nums[i];
            }
        }
        return ans1;
    }
}
```
['Java']