Beats 100%, beats 97% in memory, easy single step solution.
Intuitionjust leave the value which doesnt follow the rules given.and get the sum of the remaining numbers.Complexity
Time complexity:
O(N)
Space complexity:
O(
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
just leave the value which doesnt follow the rules given.and get the sum of the remaining numbers.
# 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)
        p = 0
        for i , num in enumerate(nums):
            if i-k >= 0 and num <= nums[i-k]:
                continue
            elif i+k < n and num <= nums[i+k]:
                continue
            else:
                p+=num
        return p
        
```
['Python3']