✅ Efficient Java Solution | O(n) Time Complexity | Simple Iteration
IntuitionA number nums[i] is considered good if:
It is strictly greater than the elements at indices i - k and i + k (if they exist).
If neither of these indice
# Intuition
A number nums[i] is considered good if:

- It is strictly greater than the elements at indices i - k and i + k (if they exist).
- If neither of these indices exist, then nums[i] is automatically good.

Thus, we iterate through the array and check if each number meets this condition. If it does, we add it to our sum of good numbers.

# Approach
1. Iterate through the array.
2. Check boundary conditions:
- If i - k exists and nums[i] <= nums[i - k], mark it as not good.
- If i + k exists and nums[i] <= nums[i + k], mark it as not good.
3. If the number is good, add it to the result sum.
4. Return the final sum of all good numbers.

# Complexity
- Time complexity: O(n)

- Space complexity: O(1)

# Code
```java []
class Solution {
    public int sumOfGoodNumbers(int[] nums, int k) {
        int good = 0;

        for(int i = 0; i < nums.length; i++){
            boolean isGood = true;

            if(i-k >= 0 && nums[i] <= nums[i-k]){
                isGood = false;
            }
            
            if(i+k < nums.length && nums[i] <= nums[i+k]){
                isGood = false;
            }

            if(isGood){
                good += nums[i];
            }
        }
        return good;
    }
}
```
['Java']