EASY SOLUTION IN JAVA 
Code


# Code
```java []
class Solution {
    public int sumOfGoodNumbers(int[] nums, int k) {
        int ans = 0;
        int f[] = new int[nums.length];
        f[0] = 0;
        for (int i = 0; i < nums.length; i++) {
            if ((i - k) >= 0&&(i + k) < nums.length) {
                f[i] = ((nums[i] > nums[i + k])&&(nums[i] > nums[i - k])) ? 1 : 0;
                continue;
            }
            if ((i - k) >= 0&&(i + k) >= nums.length) {
                if (nums[i] > nums[i - k]) {
                    f[i] = 1;
                    continue;
                }
            }
            if ((i + k) < nums.length&&(i - k) < 0) {
                if (nums[i] > nums[i + k]) {
                    f[i] = 1;
                }
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if (f[i] == 1) {
                ans = ans + nums[i];
            }
        }
        return ans;
    }
}
```
['Java']