Extremely easy solution using Ternary Operator in Python💯
IntuitionThe goal is to sum the numbers in the array that are greater than both their k-th left and k-th right neighbors.Approach
Iterate through the array.
For
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The goal is to sum the numbers in the array that are greater than both their `k`-th left and `k`-th right neighbors.

# Approach
<!-- Describe your approach to solving the problem. -->
- Iterate through the array.
- For each element:
  - Check if it's greater than the `k`-th neighbor on both sides.
  - Use conditions to handle boundary cases (avoid index out-of-bound errors).
- Add the valid elements to the total sum.

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

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$$O(1)$$

# Code
```python3 []
class Solution:
    def sumOfGoodNumbers(self, nums: List[int], k: int) -> int:
        n = len(nums)
        ans = 0
        for i in range(n):
            upper = nums[i + k] if i + k < n else 0
            lower = nums[i - k] if i - k >= 0 else 0
            ans += nums[i] if nums[i] > upper and nums[i] > lower else 0
        return ans
```
['Array', 'Python3']