1742. Maximum Number of Balls in a Box Easy

@problem@discussion
#Hash Table#Math#Counting



1/**
2 * [1742] Maximum Number of Balls in a Box
3 *
4 * You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity.
5 * Your job at this factory is to put each ball in the box with a number equal to the sum of digits of the ball's number. For example, the ball number 321 will be put in the box number 3 + 2 + 1 = 6 and the ball number 10 will be put in the box number 1 + 0 = 1.
6 * Given two integers lowLimit and highLimit, return the number of balls in the box with the most balls.
7 *  
8 * Example 1:
9 * 
10 * Input: lowLimit = 1, highLimit = 10
11 * Output: 2
12 * Explanation:
13 * Box Number:  1 2 3 4 5 6 7 8 9 10 11 ...
14 * Ball Count:  2 1 1 1 1 1 1 1 1 0  0  ...
15 * Box 1 has the most number of balls with 2 balls.
16 * Example 2:
17 * 
18 * Input: lowLimit = 5, highLimit = 15
19 * Output: 2
20 * Explanation:
21 * Box Number:  1 2 3 4 5 6 7 8 9 10 11 ...
22 * Ball Count:  1 1 1 1 2 2 1 1 1 0  0  ...
23 * Boxes 5 and 6 have the most number of balls with 2 balls in each.
24 * 
25 * Example 3:
26 * 
27 * Input: lowLimit = 19, highLimit = 28
28 * Output: 2
29 * Explanation:
30 * Box Number:  1 2 3 4 5 6 7 8 9 10 11 12 ...
31 * Ball Count:  0 1 1 1 1 1 1 1 1 2  0  0  ...
32 * Box 10 has the most number of balls with 2 balls.
33 * 
34 *  
35 * Constraints:
36 * 
37 * 	1 <= lowLimit <= highLimit <= 10^5
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/maximum-number-of-balls-in-a-box/
43// discuss: https://leetcode.com/problems/maximum-number-of-balls-in-a-box/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn count_balls(low_limit: i32, high_limit: i32) -> i32 {
49        0
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_1742() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.