Java simple readable solution
IntuitionSingle pass approach breaking down the solution into smaller methods in order to improve readability.ApproachInstead of writing everything in a single
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Single pass approach breaking down the solution into smaller methods in order to improve readability.

# Approach
<!-- Describe your approach to solving the problem. -->

Instead of writing everything in a single method, I broke it down into three methods:

- sumOfGoodNumbers - main method
- isGood - should tell us if the element is good or not
- getElementAt - a safe method to access element in a given index. Instead of throwing an IndexOutOfBoundsException, it returns 0, which is lower than the lowest element, according to the problem definition.

# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(k)
<!-- 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 (isGood(nums, i, k)) {
                sum += nums[i];
            }
        }
        return sum;
    }

    private boolean isGood(int[] nums, int i, int k) {
        return nums[i] > getElementAt(nums, i-k) 
            && nums[i] > getElementAt(nums, i+k);
    }

    // If the index is invalid, we consider nums[i] should be greater than it
    // so we just return 0 as min value is 1.
    private int getElementAt(int[] nums, int i) {
        if (i < 0 || i >= nums.length) {
            return 0;
        }
        return nums[i];
    }
}
```
['Java']