Maximum Number of Balls in a Box LeetCode solution in Java
1class Solution {2public int countBalls(int lowLimit, int highLimit) {3Map<Integer, Integer> map = new HashMap<>();4int count = Integer.MIN_VALUE;5for (int i = lowLimit; i <= highLimit; i++) {6int value = 0;7int temp = i;8while (temp != 0) {9value += temp % 10;10temp /= 10;11}12map.put(value, map.getOrDefault(value, 0) + 1);13count = map.get(value) > count ? map.get(value) : count;14}15return count;16}17}