2025-08-15 11:14:49 +0000 UTC
Maximum Number of Balls in a Box
Categories:
Links
Code
class Solution:
def countBalls(self, lowLimit: int, highLimit: int) -> int:
freqs = defaultdict(int)
max_freq = 0
for num in range(lowLimit, highLimit + 1):
box = 0
while num > 0:
box += num % 10
num //= 10
freqs[box] += 1
max_freq = max(max_freq, freqs[box])
return max_freq