4011. Smallest Absent Positive Greater Than Average
My accepted Python solution to LeetCode problem 4011, Smallest Absent Positive Greater Than Average, running in 5ms.
- Difficulty: Easy
- Python
- Runtime 5ms
- 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 5ms, memory 17.4MB, accepted 2025-12-30.
class Solution:
def smallestAbsent(self, nums: List[int]) -> int:
avg = sum(nums) / len(nums)
num_set = set(nums)
# Start from max(1, floor(avg) + 1) to ensure positive and > avg
candidate = max(1, int(avg) + 1) if avg == int(avg) else max(1, int(avg) + 1)
if avg < 0:
candidate = 1
elif avg != int(avg):
candidate = max(1, int(avg) + 1)
else:
candidate = max(1, int(avg) + 1)
while candidate in num_set:
candidate += 1
return candidate