✅ 🌟 JAVA SOLUTION ||🔥 BEATS 100% PROOF🔥|| 💡 CONCISE CODE ✅ || 🧑‍💻 BEGINNER FRIENDLY
Complexity
Time complexity:O(N)

Space complexity:O(1)
Code
# 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 sum=0;
        for(int i=0;i<nums.length;i++)
        {
            if(i+k<nums.length && i-k>=0)
            {
                if(nums[i]>nums[i-k] && nums[i]>nums[i+k])
                {
                    sum+=nums[i];
                }
            }
            else if(i+k<nums.length && 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']