Java Beats 99.99% TypeScript Beats 100%
IntuitionMy initial thought is to iterate through the array and for each element, check if it satisfies the "good number" criteria by comparing it with its left
# Intuition
My initial thought is to iterate through the array and for each element, check if it satisfies the "good number" criteria by comparing it with its left and right neighbors (if they exist).  I need to be careful about the edge cases where an element doesn't have a left or right neighbor (i.e., the first and last elements, and also the cases where `k` is greater than 1).  I'll need to accumulate the sum of the good numbers as I go.

# Approach
I will iterate through the `nums` array. For each element at index `i`, I'll check two conditions:
1. If `i - k >= 0`, check if `nums[i] > nums[i - k]`.
2. If `i + k < nums.length`, check if `nums[i] > nums[i + k]`.
If either (or both) of these conditions are true, the number `nums[i]` is a "good" number, and I will add it to a running sum.  I'll initialize the sum to 0 and return it after iterating through all the elements. I will use a boolean variable to track if the current number is a "good number" to avoid double counting if both conditions are met.

# Complexity
- Time complexity: $$O(n)$$
- Space complexity: $$O(1)$$


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

        for (int i = 0; i < n; i++) {
            // Assume it's good initially
            boolean isGood = true;

            // Check left; if NOT greater, it's NOT good
            if (i - k >= 0 && nums[i] <= nums[i - k]) {
                isGood = false;
            }

            // Check right; if NOT greater, it's NOT good
            if (i + k < n && nums[i] <= nums[i + k]) {
                isGood = false;
            }
            // Add to sum ONLY if it's still considered good
            if (isGood) {
                sum += nums[i];
            }
        }
        return sum;
    }
}
```

```typescript []
function sumOfGoodNumbers(nums: number[], k: number): number {
    let sum = 0;
    let n = nums.length;

    for (let i = 0; i < n; i++) {
        let isGood:boolean = true;

        // Check left; if NOT greater, it's NOT good
        if (i - k >= 0 && nums[i] <= nums[i - k]) {
            isGood = false;
        }

        // Check right; if NOT greater, it's NOT good
        if (i + k < n && nums[i] <= nums[i + k]) {
            isGood = false;
        }

        // Add to sum ONLY if it's still considered good
        if (isGood) {
            sum += nums[i];
        }
    }
    return sum;
};
```
['Array', 'Java', 'TypeScript']