TypeScript solution (beats 100%)
IntuitionWe can solve this problem with O(n) complexity by iterating through all items.ApproachIterating through all items in the array and calculating whether
# Intuition

We can solve this problem with O(n) complexity by iterating through all items.

# Approach

Iterating through all items in the array and calculating whether a number is good.
Using MIN_SAFE_INTEGER as a default value if k-n or k+n doesn't exist in order to simplify isGoodNumber function.

# Complexity

- Time complexity: O(n)

# Code
```typescript []
function sumOfGoodNumbers(nums: number[], k: number): number {
  let result = 0;

  function isGoodNumber(index: number): boolean {
    return (
      nums[index] > (nums[index - k] ?? Number.MIN_SAFE_INTEGER) &&
      nums[index] > (nums[index + k] ?? Number.MIN_SAFE_INTEGER)
    );
  }

  for (let i = 0; i < nums.length; i++) {
    if (isGoodNumber(i)) {
      result += nums[i];
    }
  }

  return result;
}

```
['TypeScript']