Skip to content

Commit 6cd437e

Browse files
committed
Apr 23
1 parent c503270 commit 6cd437e

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def __digit_sum(self, num: int) -> int:
3+
s = 0
4+
while num != 0:
5+
s += num % 10
6+
num //= 10
7+
return s
8+
9+
def countLargestGroup(self, n: int) -> int:
10+
counts = [0] * 37
11+
max_count = 0
12+
for num in range(1, n + 1):
13+
group = self.__digit_sum(num)
14+
counts[group] += 1
15+
max_count = max(max_count, counts[group])
16+
return sum([count == max_count for count in counts])
17+
18+
19+
def main():
20+
n = 13
21+
assert Solution().countLargestGroup(n) == 4
22+
23+
n = 2
24+
assert Solution().countLargestGroup(n) == 2
25+
26+
27+
if __name__ == '__main__':
28+
main()

2025-04-April-LeetCoding-Challenge/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
| April 19 | [2563. Count the Number of Fair Pairs](https://leetcode.com/problems/count-the-number-of-fair-pairs/) | Medium | Solved |
2626
| April 20 | [781. Rabbits in Forest](https://leetcode.com/problems/rabbits-in-forest/) | Medium | Solved |
2727
| April 21 | [2145. Count the Hidden Sequences](https://leetcode.com/problems/count-the-hidden-sequences/) | Medium | Solved |
28-
| April 22 | []() | | |
29-
| April 23 | []() | | |
28+
| April 22 | [2338. Count the Number of Ideal Arrays](https://leetcode.com/problems/count-the-number-of-ideal-arrays/) | Hard | Unsolved |
29+
| April 23 | [1399. Count Largest Group](https://leetcode.com/problems/count-largest-group/) | Easy | Solved |
3030
| April 24 | []() | | |
3131
| April 25 | []() | | |
3232
| April 26 | []() | | |
@@ -39,6 +39,6 @@
3939
## Summary
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
42-
| Easy | 6 | 6 | 0 |
42+
| Easy | 7 | 7 | 0 |
4343
| Medium | 12 | 9 | 3 |
44-
| Hard | 3 | 0 | 3 |
44+
| Hard | 4 | 0 | 4 |

0 commit comments

Comments
 (0)