<<BEAT 100% SOLUTIONS>>
PLEASE UPVOTE MECode
# **PLEASE UPVOTE ME**
# 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){
                if(nums[i]>nums[i+k]) ans+=nums[i];
            }

            else if(i>=(nums.size()-k)){
                if(nums[i]>nums[i-k]) ans+=nums[i];
            }

            else {
                if((nums[i]>nums[i+k]) && (nums[i]>nums[i-k])) ans+=nums[i];
            }
        }
        return ans;
    }
};
```
['C++']