-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay 11
More file actions
20 lines (16 loc) · 667 Bytes
/
Day 11
File metadata and controls
20 lines (16 loc) · 667 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2598.smallest-missing-non-negative-integer-after-operations
class Solution:
def findSmallestInteger(self, nums: List[int], value: int) -> int:
from collections import Counter
# Normalize each number to its modulo class in range [0, value)
freq = Counter([num % value for num in nums])
# For negative numbers, Python's % already gives non-negative remainder
# Example: -1 % 5 == 4
mex = 0
while True:
remainder = mex % value
if freq[remainder] > 0:
freq[remainder] -= 1
mex += 1
else:
return mex