Skip to content
LC-1742 Easy LeetCode

1742. Maximum Number of Balls in a Box

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 74% Topics: Hash Table, Math, Counting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(nlogm)
# Space: O(logm)

import collections
import itertools


class Solution(object):
    def countBalls(self, lowLimit, highLimit):
        """
        :type lowLimit: int
        :type highLimit: int
        :rtype: int
        """
        count = collections.Counter()
        for i in xrange(lowLimit, highLimit+1):
            count[sum(itertools.imap(int, str(i)))] += 1
        return max(count.itervalues())

Solution from kamyu104/LeetCode-Solutions · MIT