0ms 100% C and C++
Just  write each condition when sum is increased.
O(N) time complexity.C++C

Just  write each condition when sum is increased.
O(N) time complexity.

# C++
```cpp []
class Solution {
public:
    int sumOfGoodNumbers(vector<int>& nums, int k) {
        int sum = 0;
       
        for (int i = 0; i < nums.size(); ++i) {
            int lo = i - k;
            int hi = i + k;
            if (lo < 0 && hi >= nums.size()) {
              
                sum += nums[i];
            } else if (lo >= 0 && hi < nums.size()) {
                if (nums[i] > nums[lo] && nums[i] > nums[hi]) {
                     sum += nums[i];
                }
            } else if (lo >= 0 && nums[i] > nums[lo]) {
               
                sum += nums[i];
            } else if (hi < nums.size() && nums[i] > nums[hi]) {
            
                sum += nums[i];
            }
        } // for
        return sum;
    }
}

;
```

# C
```c []
int sumOfGoodNumbers(int* nums, int numsSize, int k) {

    int sum = 0;

    for (int i = 0; i < numsSize; ++i) {
        int lo = i - k;
        int hi = i + k;
        if (lo < 0 && hi >= numsSize) {
            sum += nums[i];
        } else if (lo >= 0 && hi < numsSize) {
            if (nums[i] > nums[lo] && nums[i] > nums[hi]) {

                sum += nums[i];
            }
        } else if (lo >= 0 && nums[i] > nums[lo]) {
            sum += nums[i];
        } else if (hi < numsSize && nums[i] > nums[hi]) {
            sum += nums[i];
        }
    } // for
    return sum;
}

```
['C', 'C++']