3723. Sum of Good Numbers
My accepted Python solution to LeetCode problem 3723, Sum of Good Numbers, running in 2ms.
- Difficulty: Easy
- Python
- Runtime 2ms
- Memory 17.4MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 2ms, memory 17.4MB, accepted 2025-12-31.
class Solution:
def sumOfGoodNumbers(self, nums: List[int], k: int) -> int:
n = len(nums)
total = 0
for i in range(n):
is_good = True
# Check i - k
if i - k >= 0 and nums[i] <= nums[i - k]:
is_good = False
# Check i + k
if i + k < n and nums[i] <= nums[i + k]:
is_good = False
if is_good:
total += nums[i]
return total