Imagine you're working at a magical ball factory! 🏭 You have n balls numbered consecutively from lowLimit to highLimit (inclusive), and an infinite number of boxes numbered from 1 to infinity.
Your job is to sort these balls into boxes using a special rule: each ball goes into the box whose number equals the sum of the ball's digits.
Examples of the sorting rule:
- Ball
321→ Box3 + 2 + 1 = 6 - Ball
10→ Box1 + 0 = 1 - Ball
999→ Box9 + 9 + 9 = 27
After sorting all balls, you need to find which box contains the maximum number of balls and return that count.
Goal: Return the number of balls in the most crowded box!
Input & Output
Visualization
Time & Space Complexity
Where n is the number of balls (highLimit - lowLimit + 1) and d is the average number of digits per number. Each ball is processed exactly once.
Where k is the number of unique digit sums (at most 45 for 5-digit numbers). We store one entry per unique box.
Constraints
- 1 ≤ lowLimit ≤ highLimit ≤ 105
- Ball numbers are consecutive integers
- Box numbers start from 1 (minimum possible digit sum)
- Maximum possible digit sum is 45 (for number 99999)