Easy Java Code | Beats 99% | O(n)
IntuitionWe need to find elements in the given array that are strictly greater than their neighbors at positions i - k and i + k, if they exist. If either index
## Intuition
We need to find elements in the given array that are strictly greater than their neighbors at positions i - k and i + k, if they exist. If either index does not exist, the element is still considered good.

## Approach
Iterate through the array and check each element nums[i].
Check the conditions:
If i - k exists, ensure nums[i] is greater than nums[i - k].
If i + k exists, ensure nums[i] is greater than nums[i + k].
If both conditions are satisfied (or the indices don't exist), add nums[i] to the sum.
Return the total sum of good elements.
## Complexity
Time complexity: 
O(n), as we iterate through the array once.
Space complexity: 
O(1), as we use only a few extra variables.

# Code
```java []
class Solution {
    public static int sumOfGoodNumbers(int[] nums, int k) {
        int sum = 0;
        int n = nums.length;

        for (int i = 0; i < n; i++) {
            boolean qw = true;

            
            if (i - k >= 0 && nums[i] <= nums[i - k]) {
                qw = false;
            }

            
            if (i + k < n && nums[i] <= nums[i + k]) {
                qw = false;
            }

            if (qw) {
                sum += nums[i];
            }
        }

        return sum;
    }
}
```

If you liked my solution please upvote, or comment down if you want to discuss further.
['Java']