Leetcode 1500 Solution

This article provides solution to leetcode question 1500 (count-largest-group)

https://leetcode.com/problems/count-largest-group

Solution

class Solution:
    def countLargestGroup(self, n: int) -> int:
        groups = collections.defaultdict(int)

        for i in range(1, n + 1):
            s = sum([int(ch) for ch in str(i)])
            groups[s] += 1

        max_size = max(groups.values())

        return len([1 for k, v in groups.items() if v == max_size])