1844. Maximum Number of Balls in a Box
My accepted Python solution to LeetCode problem 1844, Maximum Number of Balls in a Box, running in 204ms.
- Difficulty: Easy
- Python
- Runtime 204ms
- Memory 17.3MB
- 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 204ms, memory 17.3MB, accepted 2025-12-31.
class Solution:
def countBalls(self, lowLimit: int, highLimit: int) -> int:
from collections import Counter
def digit_sum(n):
total = 0
while n:
total += n % 10
n //= 10
return total
boxes = Counter(digit_sum(i) for i in range(lowLimit, highLimit + 1))
return max(boxes.values())