Easy & Simple Approach
IntuitionApproachComplexity
Time complexity: O(N)
Where, N is the length of an array

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

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

# Complexity
- Time complexity: O(N)
- Where, N is the length of an array
<!-- 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 n = nums.size();
        int sum = 0;
        for(int i = 0; i < n; i++){
            if((i-k >= 0 && i+k < n) && nums[i] > nums[i-k] && nums[i] > nums[i+k]){
                sum += nums[i];
            }
            else if((i-k < 0 && i+k >= n)){
                sum += nums[i];
            }
            else if(i-k < 0 && i+k < n && nums[i] > nums[i+k]){
                sum += nums[i];
            }
            else if(i-k >= 0 && i+k >= n && nums[i] > nums[i-k]){
                sum += nums[i];
            }
        }

        return sum;
    }
};

```
['C++']