O(N) solution
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
```cpp []
class Solution {
public:
    int sumOfGoodNumbers(vector<int>& nums, int k) {
        int sum=0,n=nums.size();
        for(int i=0;i<n;i++)
        {
            if(i+k<n && i-k>=0)
            nums[i]>nums[i+k] && nums[i]>nums[i-k]?sum+=nums[i]:sum+=0;
            else if(i+k<n)
            nums[i]>nums[i+k]?sum+=nums[i]:sum+=0;
            else if(i-k>=0)
            nums[i]>nums[i-k]?sum+=nums[i]:sum+=0;
        }
        return sum;
    }
};
```
['C++']