Solution using Maths
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 ans = 0;
        for (int i = 0; i < nums.size(); i++) {

            if ((i - k >= 0 && nums[i] <= nums[i - k]) ||
                (i + k < nums.size() && nums[i] <= nums[i + k])) {
                continue;
            }

            else {
                ans += nums[i];
            }
        }
        return ans;
    }
};
```
['Math', 'C++']