Maximum Number of Balls in a Box
Updated
Problem statement
You work in a ball factory. You have n balls, numbered from lowLimit up to highLimit, inclusive, so n == highLimit - lowLimit + 1. You also have an infinite number of boxes, numbered from 1 to infinity.
Put each ball in the box whose number equals the sum of the digits of the ball's number. For example, ball 321 goes in box 3 + 2 + 1 = 6, and ball 10 goes in box 1 + 0 = 1.
Given the two integers lowLimit and highLimit, return how many balls are in the box that holds the most balls.
Function
countBalls(lowLimit: int, highLimit: int) → intExamples
Example 1
lowLimit = 1highLimit = 10return = 2Box 1 receives both ball 1 (digit sum 1) and ball 10 (1+0=1), so the most-filled box has 2 balls.
Example 2
lowLimit = 5highLimit = 15return = 2Box 5 holds balls 5 and 14 (1+4=5), and box 6 holds balls 6 and 15 (1+5=6). No other box has more than 1 ball, so the answer is two.
Example 3
lowLimit = 19highLimit = 28return = 2Balls 19 (1+9=10) and 28 (2+8=10) both land in box 10. Every other box that gets a ball has just 1, so the answer is two.
Constraints
1 <= lowLimit <= highLimit <= 10^5
More Roblox Phone Screen questions
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Rate Limit by Multiple Request FieldsPHONE SCREEN · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Time-Aware Search AutocompletePHONE SCREEN · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 2026
Similar questions at other companies
- Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Average Grades per StudentHartford Financial Services · PHONE SCREENHartford Financial Services interview questions
- Median of Parsed Integer StringsRippling · PHONE SCREENRippling interview questions
- Roman Numeral to IntegerScale AI · PHONE SCREENScale AI interview questions
- Find the Missing Number from 1 to 100NVIDIA · PHONE SCREENNVIDIA interview questions
- Happy NumberSnowflake · PHONE SCREENSnowflake interview questions
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
- Max Points on a LineUber · PHONE SCREENUber interview questions
Roblox interview experiences
- Roblox OA: What It Tests (2026)
- Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
- Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
- Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
- Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
- Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)