LeetCode solutions

1500. Count Largest Group

My accepted Python solution to LeetCode problem 1500, Count Largest Group, running in 70ms.

  • Difficulty: Easy
  • Python
  • Runtime 70ms
  • Memory 17.3MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 70ms, memory 17.3MB, accepted 2025-12-30.

python
class Solution:
    def countLargestGroup(self, n: int) -> int:
        from collections import defaultdict
        groups = defaultdict(int)
        
        for i in range(1, n + 1):
            digit_sum = sum(int(d) for d in str(i))
            groups[digit_sum] += 1
        
        max_size = max(groups.values())
        return sum(1 for size in groups.values() if size == max_size)

Source