I am a beginner 😊.
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- existence of indices. -->

# Approach
<!-- cheaking for all the conditions. -->

# Complexity
- Time complexity:
<!-- O(n) , as only one loop -->

- Space complexity:
<!-- No extra spaces , O(1) -->

# Code
```cpp []
class Solution {
public:
    int sumOfGoodNumbers(vector<int>& nums, int k) {
        int n = nums.size();
        int idx = 0;
        int sum = 0;

        while(idx < n){
            if( (idx - k) < 0 && (idx + k) > (n-1) ){ // both index does not exist
                sum = sum + nums[idx];
            }
            else if( (idx - k) < 0 && (idx + k) < n ){ // idx - k does not exist
                if(nums[idx] > nums[idx + k]){
                    sum = sum + nums[idx];
                }
            }
            else if( (idx - k) >= 0 && (idx + k) > (n-1)) { // idx + k does not exist
                if(nums[idx] > nums[idx - k]){
                    sum = sum + nums[idx];
                }
            }
            else if( (idx - k) >= 0 && (idx + k) < n ){ // Both index exist
                if( (nums[idx] > nums[idx + k]) &&  (nums[idx] > nums[idx - k]) ){
                    sum = sum + nums[idx];
                }
            }

            idx++;

            
        }
        return sum;
    }
};
```
['C++']