Beats 100% of Code.
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 sum=0;
        for(int i=0;i<nums.length;i++){
            int f=1;
            if(i-k>=0){
                if(nums[i]<=nums[i-k]){
                    f=0;
                }
            }
            if(i+k<nums.length){
                if( nums[i]<=nums[i+k]){
                   f=0;                   
                }
            }
            if(f==1){
                sum+=nums[i];
            }
        }
        return sum;
    }
}
```
['Array', 'C', 'C++', 'Java']