🔥🔥🔥 Easy Solution | Java 🚀🚀
ApproachCheck the conditions and iterate through the arrayComplexity
Time complexity: O(N)

Space complexity: O(1)
Code
# Approach
Check the conditions and iterate through the array
# 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
```java []
class Solution {
    public int sumOfGoodNumbers(int[] nums, int k) {
        int n = nums.length,sum = 0;
        for (int i=0; i<n; ++i){
            if (i+k<n && i-k>=0){
                if (nums[i]>nums[i-k] && nums[i]>nums[i+k]) sum += nums[i];
            }else if (i+k<n && nums[i]>nums[i+k]) sum += nums[i];
            else if (i-k>=0 && nums[i]>nums[i-k]) sum += nums[i];
        }return sum;
    }
}
```
['Array', 'Math', 'Java']