Py/Rust check 2 conditions
IntuitionJust check two conditions and add the value if they both hold. In py you can do this with sum and comprehention.Complexity
Time complexity: O(n)
Space
# Intuition
Just check two conditions and add the value if they both hold. In py you can do this with sum and comprehention.

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

# Code


```rust []
impl Solution {
  pub fn sum_of_good_numbers(nums: Vec<i32>, k: i32) -> i32 {
    let mut res = 0;
    let k = k as usize;
    for i in 0 .. nums.len() {
      let v1 = i < k || nums[i] > nums[i - k];
      let v2 = i + k >= nums.len() || nums[i] > nums[i + k];
      if v1 && v2 {
        res += nums[i];
      }   
    }
    return res;
  }
}
```
```python []
class Solution:
  def sumOfGoodNumbers(self, nums: List[int], k: int) -> int:
    return sum(n for i, n in enumerate(nums) if (i - k < 0 or n > nums[i - k]) and (i + k >= len(nums) or n > nums[i + k]))
```
['Python3', 'Rust']